So I have several scripts that create objects and another one that needs to keep track of objects with certain properties. Is it possible to detect from that script when there is a new object created or do I have to somehow add an event trigger into the other scripts when I’m creating the objects?
If you have a script attached to the created objects you can do something like this:
public class CreatedObjectThing : MonoBehaviour {
private bool _instantiated;
public bool IsInstantiated {
get{ return _instantiated; }
}
public void Awake() {
_instantiated = true;
}
}
Then from the script from where you want to see if the object is created or not you can simply check the other objects “IsInstantiated” state.
public bool IsObjectInstantiated( GameObject go ) {
return go.GetComponent< CreateObjectThing >().IsInstantiated;
}