NodeCanvas Forums › Support › Parameters not showing in Execute Function
Hi, I’m using the Execute Function in an Action node to call a method that takes two parameters: Actor.Instance (a custom class that doesn’t derive from MonoBehavior) and a float, but when I select the method, its parameters doesn’t appear for selection, so I’d like to know if there’s a way of Actor.Instance being recognized by Execute Function — I already created a custom variable data for the class, and it’s working fine inside the BlackBoard.
Thanks in advance and best regards,
Edgard
Hello,
The Execute Function (and other ScriptControl tasks) read the available types to show which are defined within the BBVariableSet class. There are 2 solutions here, but the easiest one is to open up BBVariables.cs and go at the very last defined class called BBVariableSet.
Then un-comment from the fields declaration:
//[SerializeField]
//private BBVar systemObjectValue = new BBVar();
and from within the allVariables property un-comment at the very end:
//bbVarSet.Add(systemObjectValue);
Now with that done ALL parameter/return etc types will be shows to be selected even if not directly supported by the blackboard available types. (But you can still use ANY type with Dynamic Variables).
Unfortunately this solution needs you to change the source code for now and the reason I’ve not commented them out for realease already, is that it might become confusing for some people to show all types even if not possible to add them in the blackboard directly.
The other solution if you don’t want to change the source code is to make use the fact that BBVariableSet is partial. Let me know if you want code.
Hope that wasn’t confusing.
Cheers!
Join us on Discord: https://discord.gg/97q2Rjh
Hi, Gavalakis, thanks a lot for your prompt answer! Yep, I uncommented those lines and it worked like a charm! 🙂
Another quick question: besides creating an instance of VariableData, would there be any advantage in creating an instance of BBVar for my Actor.Instance class?
Once again, thanks a lot for your answer, and congratulations on the excellent work!
Best regards,
Edgard
Hey,
You are welcome, and thanks! I’m glad you like NC 🙂
Regarding your question, I am not exactly sure what you mean. Do you mean if there is an advantage of creating a custom BBVariable class for your type (like BBActor : BBVariable{}) ?
If this is what you mean, then there is no much point in it unless you don’t know before hand if you want to use a blackboard variable or provide an new object directly, like the floats, string etc BBVariables do. Since if you want to use a new object instance then you would simply declare it as normal in a field, whereas if you wanted to use a blackboard variable instead you can use:
[VariableType(typeof(Actor))]
public BBVar myActor;
This will show you a dropdown with all ‘Actor’ type variables within the blackboard to select one from. The only downside of this is that you need to cast the .value to your type. So creating a custom BBVariable of your type, solves this problem if it is at all. If it’s not, then there is not really a point, no : )
I hope I didn’t get confusing again. Let me know if so 🙂
By the way, please remember to un-comment those lines after you upgrade, until I figure out how I should go about it 🙂 Sorry 🙂
Best regards.
Join us on Discord: https://discord.gg/97q2Rjh
Hi, Gavalakis, once again thanks for the prompt answer, and sorry for taking too long to answer it myself!
I’ve made some tests regarding my Actor.Instance class, and here are the results so far:
1. When I remove the variable from the blackboard and create it on-the-fly (which I assume would be a dynamic variable), I’m able to test it against null inside the blackboard — is it the only way of doing this?
2. If I add a variable in the blackboard, it appears like this:
Which is not what I need, because I can’t test it for null values — is there a way of making it appear as null at first, like it happens with instances of GameObject?
3. When I add it as a BBVar using this code:
1 2 |
[VariableType(typeof(Actor.Instance))] public BBVar ActorInstance; |
It appears like this on the Inspector:
Am I doing something wrong?
Also, I have a question about the FSM, but I’ll save it to another post. 🙂
Thanks in advance and best regards!
Edgard
Hello again,
The way it works is that an instance of your custom class is created automaticaly. This is also exactly what happens if you declare a public (or [Serializable] private) variable in a MonoBehaviour (so that it can be inspected).
So, at least at this point, a custom class variable can not be null. The best way to work with it, would be with dynamic variables.
I will see for the next version to start a custom class variable as null and create an instance optionaly thought.
As for your 3rd question, it seems that you are declaring this on a typical MonoBehaviour class instead of an ActionTask or ConditionTask. Am I correct?
Cheers 🙂
Join us on Discord: https://discord.gg/97q2Rjh