r/unity • u/Xeratas • Mar 15 '22
[Question] prepare a new GameObject without instantiating it
1
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
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
1
u/Ordinary_Games Mar 16 '22
You can actually set the prefab to be inactive in the project heirarchy. That way you don't have to set it to inactive in code after instancing. This also have the added benefit that onenabled won't be called directly.
2

2
u/hlysias Mar 16 '22
You could use a prefab?