Hello,
I’ve got a weird problem here… let me try to explain the setup:
I’ve got a script here, that will import a model in runtime, and, through a config file, will add components and set a few values, based on the script. So far so good.
The thing is, once loaded, I’m not ready to have the imported objects on stage yet… so I parented them to the loader object (the one running the import script), and disabled them, so they’re there, but invisible.
Then, when I want a new object on scene, I’m calling Instantiate on this disabled, “source” object, as if it were a prefab. (In fact, this whole setup is to emulate prefab instantiation, only at runtime)
The problem, is that, for some reason, the instantiated copy comes with all it’s children in duplicate…
It’s very weird… I’m only calling Instantiate once, and even if that were the case, it would have produced 2 copies, instead of a single one with duplicate children…
Here’s a hypothesis:
The imported object isn’t stored just as it came in from the importer… First, I rename the imported object to “model”, and parent it to a new, empty gameObject I’ve created. This empty gameObject is the actual root of the object, and it holds the master component for it, and has the model, some particle effects, and another object that holds a meshcollider as it’s children. So, the imported model is only a child of a bigger object I’m constructing.
The object hierarchy tree then, looks like this:
-MyObject
-model
-modelChildObject
-anotherModelObject
-collider
-particle effects
Now, when I call Instantiate, what I get is this:
-MyObject
-model
-modelChildObject
-modelChildObject
-anotherModelObject
-anotherModelObject
-collider
-particle effects
So, it seems that somehow the imported model is taking it upon itself to re-instantiate it’s children, but what happens is that having already been instantiated, this results in duplicate children…
So, why could this be happening? Somehow the Instantiate thing is propagating itself beyond what is needed of it…
I realize it might be very hard to understand what’s happening here, since it’s quite a complex setup… My game is getting past that point where one can ask for help, since most problems are now dependent on it’s own logic…
But please, if you have any thoughts about this, do share your ideas
As always, thanks in advance!!
Cheers