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

AddPersistentListener - substitude when building the game

Discussion in 'Scripting' started by angel1st, Dec 31, 2019.

  1. angel1st

    angel1st

    Joined:
    Nov 16, 2019
    Posts:
    35
    Hi there,
    I use UnityEventTools.AddPersistentListener to add listeners when building my game levels. However, when the time comes to build the game, it seems UnityEventTools is part from UnityEditor.Events
    My question is - how can I use AddPersistentListener to add listeners for game built?
     
  2. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Just use AddListener instead. Alternatively save out the scenes on build.
     
  3. angel1st

    angel1st

    Joined:
    Nov 16, 2019
    Posts:
    35
    Thanks, @Kiwasi - actually, the only code change I did was to add preprocessor directive #if UNITY_EDITOR inside the script. Since in editor mode all required listeners are created and serialized, they can be used later on, when the game is built.