- Home /
How to access varibles on a newly instantiated object
I want to instantiate an object and then vhane one of the variables of the newly instantiated objects but Instantiate only returns an object of the class Object which isn't what I want as far as I understand from all of the instructions i've seen
Is there any way to asign the variable during instantiation or afterwords?
Answer by tanoshimi · Jan 13, 2015 at 12:51 PM
Look at the second example in the documentation for Instantiate, which sets the velocity of a newly instantiated object.
http://docs.unity3d.com/ScriptReference/Object.Instantiate.html
Answer by AndresBarrera · Jan 13, 2015 at 01:20 PM
Try something like this:
MyClass newClassObject = Instantiate(myClassPrefab) as MyClass;
//Now you can access variables and functions on 'newClassObject' as any MyClass object... as long as your 'myClassPrefab' was a real prefab with a MyClass script attached to it
Your answer
Follow this Question
Related Questions
access instantiated object variable 0 Answers
Instantiated gameObjects can't find each other 0 Answers
Mouse Over, Mouse Down, and Instantiate. 1 Answer
Help with variables 2 Answers
Problem trying to access values from another object script 0 Answers