1

I have serializable dictionary, and I try to add unity event on normal mode, but the reference for that event is loss after entering play mode.

Basically what i try to achieve here is, I add new unity event with script in a dictionary and also list, so basically the unity event in the list are the reference from the dictionary. but once i enter play mode, the unity event are not the same instance anymore.

ON EDIT MODE enter image description here

ON PLAY MODE enter image description here

It took me more than 3 days of research about serializable dictionary after i decide to ask question here.

OnBegin is serializable dictionary that i inherit from SerializableDictionary<int, UnityEvent>. OnBeginExpose is normal serializable list.

[SerializeField]
public MyDictionaryEntry OnBegin = new MyDictionaryEntry();

[SerializeField]
public List<UnityEvent> OnBeginExpose = new List<UnityEvent>();

This is how i try to add the unity event dynamically.

[System.Serializable]
public class CaptionEvent : UnityEvent{};

Dynamically add unity event with custom editor

CaptionEvent newEvent = new CaptionEvent();
eventsAuto.OnBegin.Add(i, newEvent);
eventsAuto.OnBeginExpose.Add(newEvent);

I heard about Object.GetInstanceID() that might be a solution, but i have no idea how it works. Anyone have good reference for above issues ?

3
  • I'm not sure about understanding your question, but know that when you add listener to your event in run time the Unity doesn't show it, although it is added. Maybe the problem is. Commented Jun 16, 2017 at 11:49
  • Im not adding listener/unityevent on runtime. Sorry maybe i put wrong details, i just edit the question Commented Jun 19, 2017 at 1:08
  • Its sounds like you're reigstering the listener to a reference that is override by your Awake function Commented Jun 21, 2017 at 16:28

1 Answer 1

0

You did not wrote that you use SerializableDictionary from http://wiki.unity3d.com/index.php/SerializableDictionary, am I right?

Show us meaningfull part of MyDictionaryEntry class because if you have

public class MyDictionaryEntry : SerializableDictionary<K, V> { }

without constructor it will not work. Your problem is specific to your code. There must be part witch clears all delegates from UnityEvent at element 1 or create new UnityEvent at place.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.