Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Bug Gameobject is already being activated

Discussion in 'Scripting' started by dicendprice, May 11, 2024.

  1. dicendprice

    dicendprice

    Joined:
    Oct 14, 2022
    Posts:
    3
    Hello. I encountered this problem and don't know why or how to fix it.
    I have a cloud spawn script. If the cloud goes beyond the boundaries of the collider, I move it to another point. I'm using the object pool pattern, so I activate and deactivate clouds. The error occurs when exiting the game or changing scenes.
    Apparently there is an unnecessary miscalculation.
    Help me please.

    Sorry for my english, im not english-speaking.
    upload_2024-5-11_21-7-58.png upload_2024-5-11_21-8-15.png
     
  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    6,922
    I can imagine the following scenario: the game object where CloudSpawner line 37 is attached to has just been activated or deactivated from another component's event methods. This is likely forbidden, to prevent a chain of OnEnable/OnDisable (or other events like OnTrigger) calls bouncing between several gameobject's components - eventually throwing a stack overflow.
     
    dicendprice likes this.
  3. dicendprice

    dicendprice

    Joined:
    Oct 14, 2022
    Posts:
    3
    Thank you very much for your answer. I just fixed this error. I used Object Pool, although I never turned off the clouds, so I always turned them on. It was my mistake)