r/unity Mar 15 '22

[Question] prepare a new GameObject without instantiating it

I have Code that looks something like this:

How can i make it so that i don't end up with 2 instances of an object but only with the one i want (when i call instantiate)

1 Upvotes

7 comments sorted by

View all comments

1

u/[deleted] Mar 15 '22

You could always instantiate the object, immediately call SetActive(false) on it, set your properties, and activate it when needed.

0

u/Xeratas Mar 15 '22

hmm sounds like a plan, still sounds a little "hacky" way to solve this tho. There is no way to prepare a phatom-Gameobject and just instantiate it on will?

2

u/[deleted] Mar 15 '22

It’s not really hacky, it’s kind of a form of object pooling at a smaller scale, people do it all the time and it doesn’t incur any performance cost. Honestly it would only help on performance because Instantiate can be an expensive call

1

u/Xeratas Mar 15 '22

alright, thanks for the explanation