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

Bug UnityEventTools.RemovePersistentListener dosen't save changes on an instance of a prefab.

Discussion in 'Editor & General Support' started by g_mek, Dec 7, 2022.

  1. g_mek

    g_mek

    Joined:
    Apr 11, 2022
    Posts:
    3
    Hi everyone!

    I stumbled upon this issue when trying to remove a persistent listener that was added in a prefab, let's call this Enemy, and the event 'OnDeathEvent'.
    It was set up like this: upload_2022-12-7_18-18-20.png

    In my scene, I had a bunch of instances of the Enemy prefab. Whenever I called:
    UnityEventTools.RemovePErsistentListener(enemy.OnDeathEvent, 0);
    it would remove the event as expected. Unfortunately, after starting the game the event would come back.

    Is this a known issue? Do you guys have any workarounds?
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,735
    Instances of prefabs don't exist except during playmode. There's nothing to save because the instance only exists when the game is running.

    If you want to remove a listener from the prefab, remove it from the actual prefab, not an instance.
     
  3. g_mek

    g_mek

    Joined:
    Apr 11, 2022
    Posts:
    3
    Then how are we able to change values in instances of a prefab? I thought changes in some values and changes is UnityEvents would be treated the same way.
     
  4. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,735
    Spawn the prefab, then make the changes.