Is there any way to add a script to every object being instantiated while it happens? Is there any way I can use a function that can watch every gameobject being created and run a function to add a script to it? Just wondering?
Pseudo Code
if Engine.GameObjectInstanted → call Function, pass in gameobject and then do it from there?
I believe that there’s no listener for object instantiation in the Unity and isn’t possible to redefine the instatiation methods.
Untested solution. Probably make the game slow, so I recommend to call once every 5 frames or something like this. There’s also a way to do this with tags. Put in an central update (C#):
foreach(object thisObject in FindObjectsOfTypeAll(typeof(GameObject)))
if (((GameObject) thisObject).activeInHierarchy && (GameObject) thisObject).GetComponent(YourScript) == null)
(GameObject) thisObject).AddComponent(YourScript);