Search Unity

Resolved Unity crashes and quit on play if I use a UnityEvent

Discussion in 'Editor & General Support' started by AndreaMar, Dec 28, 2022.

  1. AndreaMar

    AndreaMar

    Joined:
    Oct 29, 2019
    Posts:
    35
    Hello Unity developers.

    I'm using Unity 2022.1.18f1 and it weirdly crashes and quit when I hit the play button in the editor, but only if I use a little script attached to my character.
    This script invokes a UnityEvent when the OnControllerColliderHit function is called. The UnityEvent is then connected through the inspector to another object. Unity displays "Dynamic (name of the function I want to be called)" just above the function I want to be called, and then a list a of static parameters.
    As I've said, if I then hit the play button, Unity just quit itself. If I remove this link in the inspector then it works fine.
     
  2. AndreaMar

    AndreaMar

    Joined:
    Oct 29, 2019
    Posts:
    35
    Oh, ok. I've figured it out. It's not a bug, nor about the link in the inspector at all. It's because of a loop that goes like this:
    - controller.Move calls OnControllerColliderHit if during the move the controller collides with something;
    - OnControllerColliderHit was invoking a function where I wanted to Move the controller again;
    - asking for another Move was calling again the OnControllerColliderHit function and so on...