Gameobject changes position after play in Unity

Asked

Viewed 291 times

1

I have the following scenario:

inserir a descrição da imagem aqui

The other objects were disabled only to demonstrate the problem. I think that disabling them does not influence the game, right?

See what happens when you click on play in Unity:

inserir a descrição da imagem aqui

Note that the object Ground and Ground_2 were changed to the position (0.0) relative to the camera (yes, the pivot of the Sprite is Bottomleft, so it is not centered)

See the configuration of objects in the inspector:

Background

inserir a descrição da imagem aqui

Camera

inserir a descrição da imagem aqui

Camera script

using UnityEngine;
using System.Collections;

public class CameraSettings : MonoBehaviour {

    private float targetRatio = 9f/16f;

    // Use this for initialization
    void Start () {
        Camera cam = GetComponent<Camera>();
        cam.aspect = targetRatio;
    }
}

Ground (the 3 objects are the same, have been duplicated so the attributes in the inspector are equal):

inserir a descrição da imagem aqui

Note that the Ground, Ground_2 and Ground_3 sane prefab.
I created an Empty Gameobject (and added Recttransform, Rigidbody2d as the image above) and inside this Gameobject added a Sprite (Groundsprite) with the following settings:
inserir a descrição da imagem aqui

After the above action, I dragged the Gameobject to a Prefab and then removed the Gameobject from the scene, later I dragged the Prefab to the scene 3 times, generating the 3 elements that make up the ground (Ground, Ground_2 and Ground_3) and then went to the menu in "Gameobject > Break Prefab Instance" to be able to edit them without modifying my Prefab.

Yeah, it was a big mess, but I think the problem isn’t that I’m dragging things around, right?

What’s wrong with the game? Can it be program cache? Installation with problem? What will be?

1 answer

1

Seems to be a bug from version 5.1.2 of Unity: http://answers.unity3d.com/questions/1028760/unity-randomly-resetting-gameobjects-position-to-w.html#comment-1028775

According to the user, it solved as follows:

I Solved the problem. It was caused by the rigidbody2Ds position constraints. I Confirmed this by having few clones of the gameobject put to the Scene and ticked the Constraint off from one of them.

When the bug appeared Again, only the gameobjects with the position Y or X Frozen was reseted to the (0,0,0) position. I ticked the Constraint back on and that gameobject was also Moved to the zero position after that.

I’m not sure if that is how the constraints are supposed to work or is it a bug. But anyway that was causing the Random behaviour.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.