- Home /
Changing variable on diffirent gameobject than that the running script is attached to.
Alright guys i'm a bit stumped and i hope you guys can help me out. I have a script that creates about 7500 prefab objects and i use an XML file to decide the material and the scale. So what i currently do is on startup i run one script that sets all the object their materials and scales. But i want to change the XML file on runtime so that i can switch between datasets ingame. So what i did was i called on the script again with a diffirent XML file, and that works fine and all. But because of the size of the XML file it takes about 20seconds to run through that again. So what i want to do is run all the XML scripts on startup and save the values inside a script attached to the prefab object. So i need a way to send the variable created in one script to the specific gameobject's script. So do you guys have any ideas on this one?
Many thanks, Woox
Why not to create a special data script just with the variables to store at individual object and then attach and set the variables with the existing script?
Answer by Eric5h5 · Dec 24, 2011 at 02:50 PM
This is covered in the docs: http://unity3d.com/support/documentation/ScriptReference/index.Accessing_Other_Game_Objects.html
yeah but how would you recommend i name all those variables? Eventually i will have about 24 values per object. So that means i have to store 180.000 values. So if i use an array for each of the 24 values i would need so have an array that stores 7500 values. And a big problem would be linking the values to the diffirent gameobjects.
Your answer
![](https://koobas.hobune.stream/wayback/20220613062345im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
What makes a prefab alter their variables at runtime? 2 Answers
cant set object in prefab object, but can in the scene 1 Answer
same script on multiple objects access to different variables from another script 0 Answers
Finding the Sum of Values of Multiple GameObjects in an Array + Variable Sized arrays 0 Answers
How do I switch between multiple gameobjects during run time. 1 Answer