NodeCanvas Forums › Support › BUG (critical): ActionListPlayer deserialization › Reply To: BUG (critical): ActionListPlayer deserialization
Yes, that – since you said “OnValidate() is not really called during serialization as far as I know”.
Other than that, have you had the time to look at the error?
The following is my current modified version (based on 2.6.2), and it seems to work.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
using UnityEngine; using System.Collections.Generic; using NodeCanvas.Framework; using ParadoxNotion.Serialization; namespace NodeCanvas{ [AddComponentMenu("NodeCanvas/Action List")] [ExecuteInEditMode] public class ActionListPlayer : MonoBehaviour, ITaskSystem, ISerializationCallbackReceiver { [System.NonSerialized] private ActionList _actionList; [SerializeField] private Blackboard _blackboard; [SerializeField] private List<Object> _objectReferences; [SerializeField] private string _serializedList; public void OnBeforeSerialize(){ _objectReferences = new List<Object>(); _serializedList = JSONSerializer.Serialize(typeof(ActionList), actionList, false, _objectReferences); } public void OnAfterDeserialize(){ _actionList = JSONSerializer.Deserialize<ActionList>(_serializedList, _objectReferences); if (_actionList == null) _actionList = (ActionList)Task.Create(typeof(ActionList), this); } void Awake() { if (_actionList != null) SendTaskOwnerDefaults(); } //////// //////// public ActionList actionList{ get {return _actionList;} set {_actionList = value; SendTaskOwnerDefaults();} } public Component agent{ get {return this;} } public IBlackboard blackboard{ get {return _blackboard;} set { if ( !ReferenceEquals(_blackboard, value) ){ _blackboard = (Blackboard)(object)value; SendTaskOwnerDefaults(); } } } public float elapsedTime{ get {return actionList.elapsedTime;} } public Object contextObject{ get {return this;} } public static ActionListPlayer Create(){ return new GameObject("ActionList").AddComponent<ActionListPlayer>(); } public void SendTaskOwnerDefaults(){ actionList.SetOwnerSystem(this); foreach(var a in actionList.actions){ a.SetOwnerSystem(this); } } void ITaskSystem.SendEvent(ParadoxNotion.EventData eventData){ Debug.LogWarning("Sending events to action lists has no effect"); } [ContextMenu("Play")] public void Play(){ if (!Application.isPlaying) return; Play(this, this.blackboard, null); } public void Play(System.Action<bool> OnFinish){ Play(this, this.blackboard, OnFinish); } public void Play(Component agent, IBlackboard blackboard, System.Action<bool> OnFinish){ actionList.ExecuteAction(agent, blackboard, OnFinish); } public Status ExecuteAction() { return actionList.ExecuteAction(this, blackboard); } //////////////////////////////////////// ///////////GUI AND EDITOR STUFF///////// //////////////////////////////////////// #if UNITY_EDITOR void Reset(){ var bb = GetComponent<Blackboard>(); _blackboard = bb != null? bb : gameObject.AddComponent<Blackboard>(); _actionList = (ActionList)Task.Create(typeof(ActionList), this); } #endif } } |