Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Unity crashes after adding a tile in script.

Discussion in 'Scripting' started by FunGame2022, Jun 30, 2023.

  1. FunGame2022

    FunGame2022

    Joined:
    Jun 26, 2023
    Posts:
    3
    I'm making a 2d game with a level editor integrated into the game, the script was made with Chatgpt, at first it worked fine, now I select the tile (Debug indicates the correct selected tile), after adding it to the scene/Level unity crashes, I also tried it after compiling the game also crashes. Whatever it may be, the script has an erase and fill function. The script has a variable where I add the tiles that unity creates with the tile palette and that creates category buttons and buttons for each tile. At first it added the tiles by clicking and dragging, but out of nowhere after some modifications it makes unity crash. Can anyone help me why this happens, I'm a beginner, I don't find many tutorials on 2d level editor, the ones I find are not what I want.
    Script: https://drive.google.com/file/d/1e1WwVMOtrgncv6NRXqExZvJjlflNEobi/view?usp=sharing

    Captura de Ecrã (695).png Captura de Ecrã (696).png Captura de Ecrã (698).png
     

    Attached Files:

  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,563
    Perhaps you inadvertently made an infinite loop?

    Unity will lock up 100% of the time EVERY millisecond your scripting code is running.

    Nothing will render, no input will be processed, no Debug.Log() will come out, no GameObjects or transforms will appear to update.

    Absolutely NOTHING will happen... until your code either:

    - returns from whatever function it is running

    - yields from whatever coroutine it is running

    As long as your code is looping, Unity isn't going to do even a single frame of change. Nothing.

    No exceptions.

    "Yield early, yield often, yield like your game depends on it... it does!" - Kurt Dekker
     
    FunGame2022 likes this.
  3. FunGame2022

    FunGame2022

    Joined:
    Jun 26, 2023
    Posts:
    3
    Thanks for your attention, if the script has a loop, but in which part? At first it worked fine until adding more functions it got like this. It will be through the click and drag function to add the tiles (will this be the loop?!).
     
  4. FunGame2022

    FunGame2022

    Joined:
    Jun 26, 2023
    Posts:
    3
    I just figured out the problem, it was an infinite loop bug causing the unity to crash. I think it was the mouse click and drag function and add blocks. I separated the eraser and fill tools into separate scripts and redid the tiles script, for now it's working. Sorry for wasting your time, but here it is for someone who has the same problem.
     

    Attached Files:

    Last edited: Jul 1, 2023