NodeCanvas Forums › Support › [BUG] Blackboard losing UnityEngine.Object references
Tagged: Blackboard references lost
My team’s having problem of Blackboard keep losing the UnityEngine.Object references when Unity import the prefab from every other environment.
Reimporting or opening prefab manually fixes references.
Is there any solution or walkaround of this?
Currently we made AssetPostProcessor that forcefully reimport imported Blackboard and it takes long long time.
Unity version 2019.4/2020.3
Hello and sorry for the very late reply!
What Unity version are you using please so that I can run some tests?
Thank you!
Join us on Discord: https://discord.gg/97q2Rjh
Hello, I experienced this on Unity version both 2019.4.19f1 and 2020.3.4f1.
NodeCanvas version 3.1.8 and before.
Hmm. Just to clarify, I can see that the blackboard is a prefab. Are the lost references you mention also prefabs (or assets) or are they scene object references? Does this behaviour happen on the original Blackboard Prefab or on a Blackboard Prefab instance in the scene. I am just trying to replicate your setup, so it would be great if you can please share more details on that setup you currently have and facing this issue.
Thank you!
Join us on Discord: https://discord.gg/97q2Rjh
Yes, both blackboard and references are prefabs, and the bug happens in original blackboard prefab.
It is very easy to replicate.
Hello again and thanks for the reproduction steps.
I was able to reproduce this on my end, however I also found out a weird Unity behaviour. This problem exists only if you create new empty prefabs via the right click -> Create -> Prefab menu in the Assets tab directly. If on the other hand you create prefabs the “old way”, meaning by creating the gameobject in some scene and drag & drop that gameobject in the assets, then this problem does not occur at all and no reference is lost. It seems to me like an issue with the “Create/Prefab” command which was added in Unity 2019+.
Can you please confirm my findings that using the old way (drag and drop prefab) does indeed work correctly for you as well?
Thank you.
Join us on Discord: https://discord.gg/97q2Rjh
Hello again. I didn’t even realize there was Create/Prefab menu. I made it in ‘old way’ and still happens to me.
Hello again and very sorry for the late reply.
I tried once again and I was able to reproduce this time. The reason why it worked the previous time (thus my previous post) is because a prefab instance was still saved in the scene and apparently that helped in avoiding the problem for some reason.
After a few hours of looking into the problem, I got a few leads related to the json UnityObject serialization handling. Unfortunately I am still not able to fully fix this, but a fix is of course something that needs to be done. I just wanted to let you know that I am looking into this and I will update you in this thread as soon as I have a solution.
Thank you for your patience.
Join us on Discord: https://discord.gg/97q2Rjh
Hello, it has been a while.
Just wanted to check. Is there any update on this issue?
Thank you.
Hello there,
I am really sorry but unfortunately I wasn’t able to fully work on this for the past two weeks due to other matters. To be honest, it is also one of the hardest issues I’ve come across to fix because from my leads it really has to do with the internal Unity UnityEngine.Object handling and life-cycle. However, now that I am back from those other matters I will attack this issue again.
Thank you.
Join us on Discord: https://discord.gg/97q2Rjh
I’m also facing this issue, but in my case when referencing an InputActionReference (which is a ScriptableObject from the New Input System) in a custom condition task. When trying to edit the sub-graph (owner is NOT a prefab) I get the following error message:
Restarting Unity fixes this, but what leads me to believe it’s the same problem that Maxwell is facing is that after following his reproduction steps the error message and even the stacktrace are identical to mine (see attached screenshots).
Are there any updates on this issue?
Thanks in advance.
Edit: I’m using Unity 2021.1.19 and NodeCanvas 3.2.1.
Just came here to say that this is a very annoying bug and currently we are looking for workarounds to avoid using Blackboard.
UPDATE
I have investigated into it a bit. When Unity launches Blackboard.SelfDeserialize is called. But at that moment all _objectReferences are null. I think this is because Unity overrides operator == and at the moment referenced prefab is not awaken yet.
UPDATE 2
See my next comment on page 2 of this thread.
Yeah, I’m really liking NodeCanvas, the workflow is awesome, but seeing other posts from people having serialization problems too and the developer not being very active lately in the forums is a bit worrying 😕
Did a quick research and it seems to be related to the way Unity handles ISerializationCallbackReceiver.OnAfterDeserialize (which is used in both Blackboard.cs and Graph.cs):
https://forum.unity.com/threads/proper-use-of-onafterdeserialize.499076/#post-3245891
Unity deserializes all UnityEngine.Object’s in a different thread, which would explain why those references are not ready yet during the blackboard/graph deserialization methods.