Search Unity

  1. Unity 2020.1 has been released.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Dispose instance of IInputActionCollection generated from Input Action asset

Discussion in 'Input System' started by huulong, Feb 24, 2020.

  1. huulong

    huulong

    Joined:
    Jul 1, 2013
    Posts:
    62
    I noticed that the Input Action asset generate a C# class that implements both IInputActionCollection and IDisposable, but the examples never call Dispose(), which means the asset created from JSON is never destroyed.

    Code (CSharp):
    1. public class @InputActionsCharacter : IInputActionCollection, IDisposable
    2. {
    3.     public InputActionAsset asset { get; }
    4.     public @InputActionsCharacter()
    5.     {
    6.         asset = InputActionAsset.FromJson(@"{...}");
    7.     }
    8. ...
    9.     public void Dispose()
    10.     {
    11.         UnityEngine.Object.Destroy(asset);
    12.     }
    13. ...
    14. }
    15.  
    Should I call it on destroy in my control script?

    Code (CSharp):
    1. public class MyPlayerScript : MonoBehaviour
    2. {
    3.     private InputActionsCharacter m_InputActionsCharacter;
    4.  
    5.     private void Awake()
    6.     {
    7.         m_InputActionsCharacter = new InputActionsCharacter();
    8.     }
    9.  
    10.     private void OnDestroy()
    11.     {
    12.         m_InputActionsCharacter.Dispose();
    13.     }
    14. }
    15.  
     
  2. JTAU

    JTAU

    Joined:
    May 12, 2019
    Posts:
    6
    I've had some issues with this as well. Should InputAction be disposing itself or should we be manually doing the above?
     
unityunity