- Home /
Making one gameobject equal to another gameobject?
what will happen if we make one gameobject equal to another gameobject? (gameobject1=gameobject2)
Assume that both gameobjects have several scripts attached to them and both gameobjects have a few children. PS: gameobject1 and gameobject2 are both from different prefabs.
Answer by DannyB · Jul 12, 2013 at 11:25 AM
If you do gameObject1=gameObject2
, you will lose the reference to the actual gameObject1, and both variables will point to the same object (meaning, if you destroy gameObject2, gameObject1 will also become null).
Also note that gameObject1 doesn't go away. Like Danny said, you just lose the variable reference to it.
Answer by kavanavak · Jun 16, 2018 at 02:00 AM
Is there an easy way to set one GO to equal another?
eg. I have a dummy object that (filler/default figure GO) that I want to replace with the players chosen figure at runtime after the selection is made.
I want to take the empty "Face" GO and replace it with user selected "Face" GO without having to replace the mesh, the materials etc all individually.
as stated above setting them = just moves assignment around, rather than replacing the 'dummy' GO with the selected
GameObject gameobject2 = Instantiate(gameobject1) is what you need , just set the gameobject2 parent to the same as the gameobject1 same for the local position and rotation so that it's in the same positions as the go1 then destroy the gameobject1
Answer by y0kkaboom · Nov 26, 2018 at 04:09 PM
Well, it's quite heavy for your scene and really sketchy but you can make 2 object with the same x,y,z values and then switch which one is active when you need it, but it's like patchwork and I don't really like it. It's "KIND OF" a solution...
Well If someone knows how to do it properly I would be glad 'cause i need it to... <3
Your answer
Follow this Question
Related Questions
Gui.Button An argument is missing. ((Rest Of Code Works Fine Expt for this one Line.)) 0 Answers
Class hierarchy design and class comumication question. 1 Answer
Particle System Scripting help 1 Answer
How to Start CutScene (eventScene) with a Script? 0 Answers
How to replace a GameObject by script and keep references to it intact? 0 Answers