Say I have 5 different types of enemies.
On game startup, I instantiate one copy of each of them.
I then run a bunch of scripts on each of those instances to “prep” them for gameplay (adding fx, hooking up AI, creating collision boxes, etc.)
Then, when I actually need one of those enemies in the game, I instantiate the “prepped” instance.
Sure, I could run all of the prep work on each instance as I spawn it, but there’s a framerate hit when doing so, so why not just do it once?
The problem: Many of the variables that I’ve set during the “prep” phase are lost during the second Instantiation. Mainly seems to be variables pointing to other components on/under the object, like collision.
E.g. in my “prep” stage, I’ll set
m_visibilityCollision = transform.Find("VisColl").GetComponent<BoxCollider>();
But when I instantiate the “prepped” instance, m_visibilityCollision is null.
How can I ensure Instantiate creates a full copy of a modified source prefab?
Thanks for any suggestions!
-Scott