- Home /
Object changes its positions for no reason
Hello guys.
I'm having a problem and I can't figure out what's wrong. I'm making a 2D infinite run style game. My character is in the middle of the screen and I placed 2 objects at the right end and left end of the screen. The one on the right spawns enemies and the left one destroys them if they get to it. I have one reference to the spawning object in order to start or stop spawning enemies. My problem is that at random executions of my game both of those objects repositions themselves to (0, 0, 0) for no reason. I have nowhere in my game and code to affect their position or the objects in general. Did someone else have this problem?
Thanks in advance.
Can you please post the code so i can make a better analysis?
Also, why don't you destroy enemies with the function OnBecameInvisible? Assu$$anonymous$$g that you want they to be destroyed when they are out of the camera vision.
Additional notes which might be helpful would include ti$$anonymous$$g of this issue, current activity when it occurs and a little more context for the game itself.
For examples of what types of information might be useful (if relevant):
Ti$$anonymous$$g of the Issue: When does it happen? Is it when the character touches anything in particular? Is it when airborne? Are the enemies in any specific locations?
Current Activity: Did an enemy just spawn? Did an enemy just despawn? Does Unity list an error at the same time as the objects move to (0, 0, 0)?
Context for the Game: Is the character actually moving, or does the world move around the character? If the character is moving, how far does he travel before this problem occurs?
With a little more information and a step back for a broader look at what you're making, hopefully we can get this figured out.
I've actually had this happen to me too, on child objects of prefabs.