- Home /
Confirm Instantiation or Object Confirm it's Instance
Greetings,
I kinda have an argument here. So I need to know, what would be better in a case of having different ways of spawning enemies and keeping these enemies in memories as integer variables.
Make each type of spawning confirm that an object has been correctly instantiated or make enemies simply confirm their existence when the awake?
Edit: Here a more thorough explanation, perhaps I wasn't clear enough. I keep tabs on my instantiated objects with an Array : Int with each Int pointer representing a certain object. This enable me to keep in memory Objects across several scenes, using a very low memory footprint.
So what I'm actually asking is, keeping in mind there's multiples scripts that can instantiate these objects. Is it better to have each scripts confirm the existence of the object they spawned which get me to simply copy the same code across several scripts or simply have a script attached to my objects that let them confirm their existence?
Answer by davidt · Jan 16, 2012 at 02:28 AM
The instantiated objects won't be integer variables, they will be of type GameObject. If you just want to confirm that they instantiated OK, check the return value from your instantiate call. If it is null, then something went wrong.
In any case if you need to reference them later you'll need do this anyway so you can add the returned object to an array etc.
I already know it won't be an Integer, perhaps I wasn't clear enough. I edited my post with the relevant info.
Answer by Tasarran · Jan 16, 2012 at 03:32 AM
You can do this:
var instance : GameObject;
instance = Instantiate(Prefab, Position, Rotation);
Debug.Log(instance);
You could also Add each one to an array as you create them.
This not at all what I seeked, please read thoroughly before answering.
Or comment for precisions if you're not sure.
Your answer
Follow this Question
Related Questions
Development / Live Build Coding 0 Answers
[SerializeField] for self components instead of GetComponent<>? 1 Answer
Keeping track of which areas remain unexplored 1 Answer
Network.Instantiate/Destroy vs Instantiate/Destroy on each client using [Command] and [ClientRpc] 1 Answer
Is it legal to copy the Resident Evil Spencer mansion for my game? 0 Answers