How do I access an Instantiated object?

So, pretty far into the game I stumble onto a problem… I can not access an instantiated object. I do not know how, because I am relatively new into this language. I have tried using for example “name = Instantiate” but I still can not access the rigid body of the instantiated object. Also I need help in connecting a scrip to an instantiated object. For example i have one instantiated object with a script attached to it which is giving the player the ability to move the object with the mouse, but as I click on the Instantiated object it comes out as an error = “Object reference not set to an instance of an object”. Could it be because it is a copy of the original?

You can access the gameobject with this (in C#):
GameObject instantiated = (GameObject)GameObject.Instantiate…
you can get the rigidbody with instantiated.GetComponent()
connecting a script? you mean adding a component:
instantiated.AddComponent()
And the last one is something you haven’t done, there’s nothing that changes when something is a clone
You’ve probably done some initialization in the Start() and that wont run

4 Likes