- Home /
Adding a script in Editor moves GameObjects back to Origin.
I just stumbled upon a strange behaviour in Unity. I have this simple script below and when I attach it to any gameobject while the game is NOT running, it moves the gameobject to the origin. If I start the game and add it at runtime, everything works fine.
It's easy to work around this, but it's still annoying and I'd like to know what causes that. Here's the script :
private Vector3 defaultPosition;
void Start () {
gameObject.layer = 9;
gameObject.tag = "Grabbable";
defaultPosition = transform.position;
}
public void Reset() {
Debug.Log ("RESET CALLED");
transform.position = defaultPosition;
}
Answer by Krizzen · Jun 07, 2014 at 02:43 PM
The method **`Reset`** is called when the Component is first added while inside Unity's editor. Consider renaming your Reset method unless you want it to take effect in the editor.
Ahhhh. That explains it, I didnt know about the Reset $$anonymous$$ethod, Thank you.
Your answer
![](https://koobas.hobune.stream/wayback/20220613151015im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Help with Grid movement script + AI script 1 Answer
Perform action on save/load in editor 2 Answers
Stopping all movement along axis? 1 Answer
Custom Asset Icons? 2 Answers