Reply To: BUG (critical): ActionListPlayer deserialization

NodeCanvas Forums Support BUG (critical): ActionListPlayer deserialization Reply To: BUG (critical): ActionListPlayer deserialization

#11651
bcristian
Participant

Oops, I’ve made a mistake when merging your new version with the old one modified by me, the new one doesn’t have the OnValidate, it calls SendTaskOwnerDefaults directly from OnAfterDeserialize.
The end result is the same though, as it still uses API’s not usable at that time.

But it gets even weirder.

All of the following happens in a new project, only NodeCanvas imported (none of my changes), Unity 5.5.0f3.

https://docs.unity3d.com/ScriptReference/MonoBehaviour.OnValidate.html
This function is called when the script is loaded or a value is changed in the inspector (Called in the editor only).

New scene, new empty GO, add the script, save, new scene, open the previously saved scene.
On my machine, it prints out “OnValidate” every time. Does the same happen on your side?

New scene, new global BB and new ActionListPlayer. Add an integer to the BB, and an action to increment said integer in the ALP.
Save, new scene, open the previously saved scene.

And now the weird part.
If Android is set as the build target, I get these 2 errors:
FindObjectsOfType is not allowed to be called during serialization, call it from Awake or Start instead. Called from MonoBehaviour ‘ActionListPlayer’ on game object ‘ActionList’.
See “Script Serialization” page in the Unity Manual for further details.
UnityEngine.Object:FindObjectsOfType()
NodeCanvas.Framework.GlobalBlackboard:Find(String) (at Assets/ParadoxNotion/NodeCanvas/Framework/Runtime/Variables/GlobalBlackboard.cs:42)
NodeCanvas.Framework.BBParameter:ResolveReference(IBlackboard, Boolean) (at Assets/ParadoxNotion/NodeCanvas/Framework/Runtime/Variables/BBParameter.cs:270)
NodeCanvas.Framework.BBParameter:set_bb(IBlackboard) (at Assets/ParadoxNotion/NodeCanvas/Framework/Runtime/Variables/BBParameter.cs:175)
NodeCanvas.Framework.BBParameter:SetBBFields(Object, IBlackboard) (at Assets/ParadoxNotion/NodeCanvas/Framework/Runtime/Variables/BBParameter.cs:54)
NodeCanvas.Framework.Task:set_blackboard(IBlackboard) (at Assets/ParadoxNotion/NodeCanvas/Framework/Runtime/Tasks/Task.cs:331)
NodeCanvas.Framework.Task:SetOwnerSystem(ITaskSystem) (at Assets/ParadoxNotion/NodeCanvas/Framework/Runtime/Tasks/Task.cs:169)
NodeCanvas.ActionListPlayer:SendTaskOwnerDefaults() (at Assets/ParadoxNotion/NodeCanvas/Modules/ActionListPlayer/ActionListPlayer.cs:71)
NodeCanvas.ActionListPlayer:set_actionList(ActionList) (at Assets/ParadoxNotion/NodeCanvas/Modules/ActionListPlayer/ActionListPlayer.cs:38)
NodeCanvas.ActionListPlayer:OnAfterDeserialize() (at Assets/ParadoxNotion/NodeCanvas/Modules/ActionListPlayer/ActionListPlayer.cs:28)

UnityException: FindObjectsOfType is not allowed to be called during serialization, call it from Awake or Start instead. Called from MonoBehaviour ‘ActionListPlayer’ on game object ‘ActionList’.
See “Script Serialization” page in the Unity Manual for further details.
UnityEngine.Object.FindObjectsOfType[GlobalBlackboard] () (at C:/buildslave/unity/build/Runtime/Export/UnityEngineObject.cs:227)
NodeCanvas.Framework.GlobalBlackboard.Find (System.String name) (at Assets/ParadoxNotion/NodeCanvas/Framework/Runtime/Variables/GlobalBlackboard.cs:42)
NodeCanvas.Framework.BBParameter.ResolveReference (IBlackboard targetBlackboard, Boolean useID) (at Assets/ParadoxNotion/NodeCanvas/Framework/Runtime/Variables/BBParameter.cs:270)
NodeCanvas.Framework.BBParameter.set_bb (IBlackboard value) (at Assets/ParadoxNotion/NodeCanvas/Framework/Runtime/Variables/BBParameter.cs:175)
NodeCanvas.Framework.BBParameter.SetBBFields (System.Object o, IBlackboard bb) (at Assets/ParadoxNotion/NodeCanvas/Framework/Runtime/Variables/BBParameter.cs:54)
NodeCanvas.Framework.Task.set_blackboard (IBlackboard value) (at Assets/ParadoxNotion/NodeCanvas/Framework/Runtime/Tasks/Task.cs:331)
NodeCanvas.Framework.Task.SetOwnerSystem (ITaskSystem newOwnerSystem) (at Assets/ParadoxNotion/NodeCanvas/Framework/Runtime/Tasks/Task.cs:169)
NodeCanvas.ActionListPlayer.SendTaskOwnerDefaults () (at Assets/ParadoxNotion/NodeCanvas/Modules/ActionListPlayer/ActionListPlayer.cs:71)
NodeCanvas.ActionListPlayer.set_actionList (NodeCanvas.Framework.ActionList value) (at Assets/ParadoxNotion/NodeCanvas/Modules/ActionListPlayer/ActionListPlayer.cs:38)
NodeCanvas.ActionListPlayer.OnAfterDeserialize () (at Assets/ParadoxNotion/NodeCanvas/Modules/ActionListPlayer/ActionListPlayer.cs:28)

switch platform to PC, Mac & Linux Standalone, and now the errors when opening the scene change to:
get_isPlaying is not allowed to be called during serialization, call it from Awake or Start instead. Called from MonoBehaviour ‘ActionListPlayer’ on game object ‘ActionList’.
See “Script Serialization” page in the Unity Manual for further details.
UnityEngine.Application:get_isPlaying()
NodeCanvas.Framework.BBParameter:set_bb(IBlackboard) (at Assets/ParadoxNotion/NodeCanvas/Framework/Runtime/Variables/BBParameter.cs:162)
NodeCanvas.Framework.BBParameter:SetBBFields(Object, IBlackboard) (at Assets/ParadoxNotion/NodeCanvas/Framework/Runtime/Variables/BBParameter.cs:54)
NodeCanvas.Framework.Task:set_blackboard(IBlackboard) (at Assets/ParadoxNotion/NodeCanvas/Framework/Runtime/Tasks/Task.cs:331)
NodeCanvas.Framework.Task:SetOwnerSystem(ITaskSystem) (at Assets/ParadoxNotion/NodeCanvas/Framework/Runtime/Tasks/Task.cs:169)
NodeCanvas.ActionListPlayer:SendTaskOwnerDefaults() (at Assets/ParadoxNotion/NodeCanvas/Modules/ActionListPlayer/ActionListPlayer.cs:71)
NodeCanvas.ActionListPlayer:set_actionList(ActionList) (at Assets/ParadoxNotion/NodeCanvas/Modules/ActionListPlayer/ActionListPlayer.cs:38)
NodeCanvas.ActionListPlayer:OnAfterDeserialize() (at Assets/ParadoxNotion/NodeCanvas/Modules/ActionListPlayer/ActionListPlayer.cs:28)

UnityException: get_isPlaying is not allowed to be called during serialization, call it from Awake or Start instead. Called from MonoBehaviour ‘ActionListPlayer’ on game object ‘ActionList’.
See “Script Serialization” page in the Unity Manual for further details.
NodeCanvas.Framework.BBParameter.set_bb (IBlackboard value) (at Assets/ParadoxNotion/NodeCanvas/Framework/Runtime/Variables/BBParameter.cs:162)
NodeCanvas.Framework.BBParameter.SetBBFields (System.Object o, IBlackboard bb) (at Assets/ParadoxNotion/NodeCanvas/Framework/Runtime/Variables/BBParameter.cs:54)
NodeCanvas.Framework.Task.set_blackboard (IBlackboard value) (at Assets/ParadoxNotion/NodeCanvas/Framework/Runtime/Tasks/Task.cs:331)
NodeCanvas.Framework.Task.SetOwnerSystem (ITaskSystem newOwnerSystem) (at Assets/ParadoxNotion/NodeCanvas/Framework/Runtime/Tasks/Task.cs:169)
NodeCanvas.ActionListPlayer.SendTaskOwnerDefaults () (at Assets/ParadoxNotion/NodeCanvas/Modules/ActionListPlayer/ActionListPlayer.cs:71)
NodeCanvas.ActionListPlayer.set_actionList (NodeCanvas.Framework.ActionList value) (at Assets/ParadoxNotion/NodeCanvas/Modules/ActionListPlayer/ActionListPlayer.cs:38)
NodeCanvas.ActionListPlayer.OnAfterDeserialize () (at Assets/ParadoxNotion/NodeCanvas/Modules/ActionListPlayer/ActionListPlayer.cs:28)

Copied your new version and made it ExecuteInEditMode, moving the SendTaskOwnerDefaults to Awake (if _actionList not null) and deserializing into _actionList seems to make it work.