NodeCanvas Forums › General Discussion › Task Initialization › Reply To: Task Initialization
Hello again and very sorry for the late reply!
Some of the things you want to achieve will require few or more changes. Some of them I am willing to do for the next version as I find interesting.
– OnValidate is called from various locations and could be called more than once in the same frame. OnValidate is basically called from within Graph.OnEnable as well as (in case of bound graphs), GraphOwner.OnValidate. A few changes that could be made to ensure the agent is set during those calls would be open up GraphOwner.cs and in it’s ‘Validate’, change the order of boundGraphInstance.UpdateReferencesFromOwner
to be, before the boundGraphInstance.Validate
call as such:
1 2 3 4 |
boundGraphInstance.UpdateReferencesFromOwner(this); boundGraphInstance.Validate(); |
Another change to complement this, would be to change the Graph.OnEnable to this:
1 2 3 4 5 6 7 |
protected void OnEnable(){ if (hasDeserialized){ Validate(); } } |
This will make sure to only call OnValidate after the graph has serialized, thus avoid an OnValidate call simply because a graph has just been instantiated (since OnEnable is called when a graph is instanted too).
As a result to the above changed, you will receive a OnValidate call with the agent set correctly (if any) in the editor, but you might get more that one OnValidate calls, thus you will have to check for null agent.
– To “post” a log in the NodeCanvas Console, you can do so by using the custom logger like this:
ParadoxNotion.Services.Logger.Log(string message, string tag, object contextObject)
. Thus from within a Task.OnValidate, the ‘contextObject’, would most probably be itself (this).
Any log logged with this custom logger, will be shown in the NodeCanvas Console and will be possible to click-to-select the relevant node.
With that said though, it is not dynamic like in what you want to achieve, meaning that it will not remove itself automatically if the error is fixed. For that, I will probably need to change the OnValidate, to return a string, similar to how the OnInit does, but this will require a lot of changes to post here.
Please let me know if the above were helpful, or what other code places you might want me to point to you at regarding the things you want to achieve.
Thank you.
Join us on Discord: https://discord.gg/97q2Rjh