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

Is there any way to clear performed/started/canceled registered event listeners?

Discussion in 'Input System' started by Ratslayer, Apr 21, 2021.

  1. Ratslayer

    Ratslayer

    Joined:
    Feb 6, 2014
    Posts:
    37
    I want to disable domain reloading to speed up entering Playmode. However, every time I enter playmode, my script attaches methods to certain InputAction events. So without domain reloading, those events keep piling up. I use anonymous methods as callbacks, so I can't do a -= before adding them. Is there any method that allows clearing performed/started/canceled before adding methods to them?
     
  2. Ratslayer

    Ratslayer

    Joined:
    Feb 6, 2014
    Posts:
    37
    I didn't find any way of doing it directly. C# provides no way of resetting events, unless you have event ownership. So I just store every single delegate I add in a list and don't add the delegates unless needed.