- Home /
GameObject is already being activated or desactivated
When I jump into the moving platform they show my this error.
void OnCollisionEnter2D(Collision2D other)
{
if (other.transform.tag == "MovingPlatform")
{
transform.parent = other.transform;
}
}
void OnCollisionExit2D(Collision2D other)
{
if (other.transform.tag == "MovingPlatform")
{
transform.parent = null;
}
}
The error is this line of code:
transform.parent = null;
Answer by haizathaneefa · Jun 30, 2020 at 03:44 AM
Several things you could do first is remove the OnCollisionEnter
and have a debug log on your OnCollisionExit
to check if it really go through. Debug.Log
is a really powerful to help you figure out what is really going on.
From what you told, the gameobject doesnt have a parent to begin with. It might be because two functions are firing at the same time.
I see the problem, when my Player crouch, active the function OnCollisionExit in the same time the function OnCollisionEnter and this produce the error to GameObject Active or Desactive.
Answer by CodesCove · Jun 29, 2020 at 08:30 PM
On possible cause: This error is shown if you are trying to set the parent more than once in the same frame. So the Enter and Exit might be happening in the same frame (for some reason).
This error is caused specifically for change collider when my player crouch in a moving platform. I use setActive true or false in case when my player execute the action for crouch. I'm lose my hope to fix this.
Your answer
Follow this Question
Related Questions
How do I inherit certain varibles and functions from another script. 1 Answer
How to detect if two objects become a square ? 1 Answer
Please help my head is burning from this problem : i have multiple gameobject , same script 1 Answer
Where is the problem with the script, i want my player to die when his health is <1 1 Answer