Objects Duplicated in Memory

This may be a dumb question, and I hope the answer is that objects are not duplicated, but I am not sure so I’m asking.

If I create a List of GameObjects in my C# script, each one is set to a GameObject.Find. Multiple variables are set in this script to be GetComponent from some of those List of GameObjects.

My question for this situation, are the GameObjects that already exist, and the GameObject references in my code using the same memory, or different (double the memory) memory? Same question for the GetComponent. If I create a variable the uses GetComponent, is it using twice the memory as the Component itself, or is the variable in code simply a reference/pointer?

I guess what I’m really asking is - do GameObject.Find() and GameObject.GetComponent() use extra memory because their values are also being used in a script?

I’m hoping the answer is no, because I can imagine it would kill the performance in games with a lot of GameObjects… but I cannot be sure.

No :slight_smile:

GameObject.Find() returns a reference to the game object. It does not create a new one.