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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Can't disconnect input action callback from function

Discussion in 'Input System' started by seeleyben31, Aug 29, 2020.

  1. seeleyben31

    seeleyben31

    Joined:
    May 18, 2019
    Posts:
    1
    I'm looking to change the attached function to a unity action performed callback when I change gamestates. How to I change what function is called? How do I detach a function from the callback so that the initial function is no longer called?

    Code (CSharp):
    1.     public override void PrepareState()
    2.     {
    3.         base.PrepareState();
    4.        
    5.         // Attach functions to view events
    6.         owner.controls.Player.Fire.performed += _ => StartClicked();
    7.         owner.controls.Player.Quit.performed += _ => QuitClicked();
    8.     }
    9.  
    10.     public override void DestroyState()
    11.     {
    12.         // Detach functions from view events
    13.         owner.controls.Player.Fire.performed -= _ => StartClicked();
    14.         owner.controls.Player.Quit.performed -= _ => QuitClicked();
    15.         base.DestroyState();
    16.     }