- Home /
GameObject [,] variable will it be addresses?
I'm on the verge of creating a variable like this...
Public GameObject [,] Trees.
I want to place these objects in a 2D array to save distance calls etc, but am nagged by the possibility that each entry in this array could well contain everything within the gameobject, or just an "address" (link an integer and a type) to the point in the computer's memory.
Obviously the former would be madness and the latter would be ideal. Which is true, and is there an index somewhere showing what is stored for all unity specific variables?
With address, do you mean if what is stored is a reference to the object? Are you using C# or Javascript?
c#
Yes, I just mean is it just a reference that's stored.
Answer by Wuzseen · Mar 21, 2014 at 03:06 PM
You would indeed have a list of references to gameobjects, not deep copies of everything that game object entails.
What do you mean what is stored?
http://docs.unity3d.com/Documentation/ScriptReference/GameObject.html
Tells you everything you need to know about what is inside a game object.
I meant as in RA$$anonymous$$ impact more than anything. $$anonymous$$y code is way cleaner to the eye using direct references in a huge array, and runs faster, but worried I might get bitten by RA$$anonymous$$ further down the line.
Since they're all references, it's the size of a pointer. So, it's very, very, $$anonymous$$imal. You will not get bit by RA$$anonymous$$ further down the line. These are just some of the joys of a 'modern' language. If you instantiate 100 game objects and store them in your array, you're just making references to them in the array, it's the same impact (potentially a bit more or less) as if you just made 100 GameObject variables.
No problem!
(if you could accept it too that would be great!)
Your answer
Follow this Question
Related Questions
Object reference not set to an instance of an object 0 Answers
Sorting variable names by their values. 2 Answers
Locking the value of a variable, or something similar 2 Answers
Getting a variable from an object 1 Answer
How do variable arrays work? 2 Answers