NodeCanvas Forums › Support › Blackboard Variable Types issue
Hi Gavalakis,
I hope you are doing well,
I am trying to test how different variable types can be of benefit for my workflow, so I am testing arrays, Enum and Dictionaries
these types did not come as default in the node canvas, I have added them from the preferred types panel.
when I try to use them, I find no way to add values to them.
If I am inside an action all I see is Abstract(Enum) or Abstract(Dictionary). If I try to add values to them in the variables panel, also not possible
For your reference I am running version 2.5.6 and attaching a screenshot for your reference
I am missing a setting?
Thanks in advance!!
Hey,
It seems that you have added the abstract System.Enum type. What you need to do instead is add the actual enum you want to use, like for example UnityEngine.WrapMode, not the base type System.Enum.
Same is the problem for Dictionaries, although Dictionaries are unfortunately not really supported to be used as blackboard variables through the editor at the moment.
Let me know if adding enums works for you considering the above.
Thanks.
Join us on Discord: https://discord.gg/97q2Rjh
Hi,
it did work as you explained, with any Enum that already has predefined values,
question.. is there an option where I can create my own Enum and I define my own values? how can I do that?
thanks in advance!
one more question. Is the Dictionaries functionality planned in the short or long term?
Hey,
Enums are simply types which can be created in code likeso:
1 2 3 4 5 6 7 |
public enum MyEnum{ One, Two, Three } |
Dictionaries is something I’d like to support for variables added through the editor in the future, but I can’t really promise as of when this will be possible 🙂
Join us on Discord: https://discord.gg/97q2Rjh
Hi there,
that Enum code worked! thanks for that,
hopefully you find some time in the future to implement the dictionaries through the editor. So at this point how can use them now in nodecanvas outside the variables editor?
I am working in a fsm and want to manage a list with enemies with name and power and want to be able to locate them by name. So I want to interact the ism and perhaps some bit of coding, but can you provide me a short example with screenshots or gifs? is it possible?
thanks in advance!
Hey,
You are welcome. 🙂
You can use the Blackboard API to add any type of variable outside the variables editor and through coding. That includes adding Dictionary types.
For example, if you add this script on the gameobject that the blackboard is, you will be able to add a dictionary type through the script’s context menu, which you can do in the editor as well.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
using UnityEngine; using System.Collections.Generic; using NodeCanvas.Framework; public class Example : MonoBehaviour { [ContextMenu("AddDictionaryVariable")] void AddDictionaryVariable(){ var bb = GetComponent<Blackboard>(); bb.AddVariable("Enemies", typeof(Dictionary<string, GameObject>)); } } |
Even doing so, there are no existing actions for dictionaries though, so creating custom ones to do what you want will be required. I can help you with that of course.
Regarding your 2nd question, can you please provide a bit more info on what you will require to do with this list of enemies variable? Is “Enemy” some custom MonoBehaviour script you have created?
Let me know.
Thanks.
Join us on Discord: https://discord.gg/97q2Rjh
Hi there,
thanks very much for your answer, that gave me a good start. 🙂
regarding my 2nd question. I actually I am looking into a solution to add enemies names(string) and power(int) into a dictionary. Then I want to locate from a game object manager by name and update the corresponding power.
May I ask you a favor? can you help me to create a couple of custom actions… 1 for adding entry to the dictionaries variable and 1 for getting the value for a specified key. If then I will check how you did them and I will try to do the rest I am planning(count property, delete an entry, clear dictionary, iterate, etc.)
please let me know if that is possible,
thanks in advance!
Hey,
Sure 🙂
Bellow are the 2 Dictionary related actions you requested. Notice that both of these actions are able to work with any type of value, but only string for key. Since only one generic argument is supported in NodeCanvas at the moment, I chosen it to be string, since it is the most commonly used one of course 🙂
Both can be found under category “Blackboard/Dictionaries”. Like the rest of the generic tasks, you simply have to choose integer for your case like for example “Blackboard/Dictionaries/AddElementToDictionary (T)/AddElementToDictionary(Integer)”.
Let me know if these work for you.
AddElementToDictionary.cs
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 |
using UnityEngine; using System.Collections.Generic; using ParadoxNotion.Design; using NodeCanvas.Framework; namespace NodeCanvas.Tasks.Actions{ [Category("✫ Blackboard/Dictionaries")] public class AddElementToDictionary<T> : ActionTask { [BlackboardOnly] [RequiredField] public BBParameter<Dictionary<string, T>> dictionary; public BBParameter<string> key; public BBParameter<T> value; protected override string info{ get {return string.Format("{0}[{1}] = {2}", dictionary, key, value);} } protected override void OnExecute(){ dictionary.value[key.value] = value.value; EndAction(); } } } |
GetDictionaryElement.cs
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 |
using UnityEngine; using System.Collections.Generic; using ParadoxNotion.Design; using NodeCanvas.Framework; namespace NodeCanvas.Tasks.Actions{ [Category("✫ Blackboard/Dictionaries")] public class GetDictionaryElement<T> : ActionTask { [BlackboardOnly] [RequiredField] public BBParameter<Dictionary<string, T>> dictionary; public BBParameter<string> key; [BlackboardOnly] public BBParameter<T> saveAs; protected override string info{ get {return string.Format("{0} = {1}[{2}]", saveAs, dictionary, key);} } protected override void OnExecute(){ saveAs.value = dictionary.value[key.value]; EndAction(); } } } |
Join us on Discord: https://discord.gg/97q2Rjh
AWESOME!!
thanks Gavalakis! this will help me a lot!!