This question was
closed Jan 17, 2019 at 10:31 AM by
tormentoarmagedoom for the following reason:
Other
Question by
JATC1024 · Jan 16, 2019 at 12:22 PM ·
gameobjectproperty
How do I change GameObject properties in scripts Unity?
I'm trying to save/load my game. In the load method, everytime I change the properties of a GameObject, those changes are applied and then get converted shortly after. Here is my code:
List<GameObject> rootObjects = new List<GameObject>();
Scene scene = SceneManager.GetActiveScene();
scene.GetRootGameObjects(rootObjects);
for(int i = 0; i < rootObjects.Count; i++){
var obj = rootObjects[i];
var cpn = obj.GetComponent<Transform>();
cpn.position = player.position;
cpn.rotation = player.rotation;
cpn.localScale = player.localScale;
}
Those changes are applied to the GameObject, however they get aborted right away. How can I resolve this?
The script contains these lines of code is not a component of the GameObject.
Comment
Best Answer
Answer by JATC1024 · Jan 16, 2019 at 03:40 PM
I got a solution here: https://stackoverflow.com/questions/54216924/how-do-i-change-gameobject-properties-in-scripts-unity