Search Unity

ScriptableObject and InputSystem

Discussion in 'Open Projects' started by Nsuidara, Feb 10, 2021.

  1. Nsuidara

    Nsuidara

    Joined:
    Apr 22, 2016
    Posts:
    36
    Hello.

    I'm keep an eye on this project out of curiosity.
    And i was interesed about ScriptableObject & InputSystem.

    In Editor works fine, but when i build then I ran into a problem.
    Input System in ScriptableObject not working for me.
    I check and copy into MonoBehaviour, GameInput.IGameplayActions and attach... works fine :)

    Looks for me when i build game, then ScriptableObject never called OnEnable or Awake when game RUN :)
    Something I missing ?


    Sorry for my English, I not good at English.

    https://docs.unity3d.com/ScriptRefe...22.1192964670.1612963238-717068479.1603393356
    but not works like description :(

    [Solved]
    When in (my script) but like ~Protagonist in OnEnable i made _inputReader.OnEnable() (ofc made public) then start working

    but Why? OnEnable should works in SO too...
     
    Last edited: Feb 10, 2021
  2. cirocontinisio

    cirocontinisio

    Joined:
    Jun 20, 2016
    Posts:
    884
    Hmm, not sure how to help, when I build the game input works fine. How do you detect the error and how are you sure that OnEnable is not called in the build? I guess because it works when you do this?

     
  3. Nsuidara

    Nsuidara

    Joined:
    Apr 22, 2016
    Posts:
    36
    I'll try to explain.

    I love your idea Input System and Scriptable Object and just implement it.

    Code (CSharp):
    1. public class InputReader : ScriptableObject, GameInput.IGameplayActions
    so, next create SO
    so, next create Movement (MonoBehaviour)
    mean, like
    Code (CSharp):
    1. ...
    2.         private void OnEnable()
    3.         {
    4.             inputReader.OnEnable();
    5.             inputReader.MoveEvent += OnMove;
    6.             inputReader.JumpEvent += OnJumpInitiated;
    7.             inputReader.JumpCanceledEvent += OnJumpCanceled;
    8.         }
    9. ....
    Version IS
    upload_2021-2-12_18-51-30.png

    Play in editor works fine, when build - not working.
    (i add console, ~ show/hide) after build key ~ not working

    upload_2021-2-12_18-45-34.png

    only when i manualy run OnEnable
     
  4. cirocontinisio

    cirocontinisio

    Joined:
    Jun 20, 2016
    Posts:
    884
    Sounds like it's not an issue related to the Input System. You need to find out why the SO is not calling OnEnable. Where is the SO? In assets? Do you use AssetBundles?