This might seem like a pretty noobish and common question. And perhaps it is, but I haven’t found an approach to the same subject so I hope some of you already faced this dilemma.
I have a simple prefab which, because of a multiplayer necessity, needs be instantiated dynamically.
The point is, this object is not just dynamic in the sense that it can be randomly spawned. The very reference for it in the script does change.
So as an example, I have:
...
class explosion
Transform explosiontype;
...
Now my prefabs are in the sort of
nuclear
daisycutter
napalm
but of course since I need to instantiate that prefab at some point (they are assigned into other gameobjects arrays)
I have something like
nuclear prefab => explosiontype => nuclear prefab <= dragged into the public slot in the inspector
daisycutter prefab => explosiontype => daisycutter prefab
napalmprefab => explosiontype => napalm prefab
Well, basically this works. But it feels dirty.
I am wondering if any of you faced this dilemma already, and if this is the preferred way to solve this necessity.
Again, the ‘problem’ is the fact that in a multiplayer setting, Network.Instantiate needs a PREFAB reference, whilst the normal instantiate can do with an object.
thanks
It's not clear to me why the explosion needs a reference to itself. Surely whatever Instantiated the original explosion would already have that, and should be also responsible for creating the network instances too?
– Waz@Warwick Allison sorry if it wasn't clear, it's because of a stupid idea behind the classing, where an explosion spawns sub explosions, for which I need the base prefab to be referenced. Sadly, I two other main classes upon this logic, and rewiring them to use a global prefab reference array or list would be plain crazy.
– roamcelWell if you admit that the idea is stupid and you're too lazy to fix it, it's a little difficult to help, haha. It's UnityAnswers, not UnityHacks.
– PrimeDerektive@Derek Traver lol it is not a stupid idea per se. It's stupid because it stuck me in a problem that should not have existed to start with. And lol @ being lazy. We're talking about thousands of lines of raw code which again would never have needed an unnecessary fix for a buglike behavior. I'm sure that sits well with you too!
– roamcelDo you think Unity is wrong here? It's not. A prefab can contain references to itself and children in itself for good reasons, and these it wants converted to scene object references upon instantiation. (eg. a spring in a prefab has ref to joined Rigidbody).
– Waz