Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

NodeCanvas - (Behaviour Trees | State Machines | Dialogue Trees)

Discussion in 'Assets and Asset Store' started by nuverian, Feb 8, 2014.

  1. Sluggy

    Sluggy

    Joined:
    Nov 27, 2012
    Posts:
    960
    So it looks like I slightly misinterpreted the results I got. The graphs do, in fact, only deserialize once. However, I am getting the results I see because it appears that the deserializer doesn't kick in until the graph actually updates. Is there a way I can force it to deserialize after instantiation that doesn't require me to leave the game object active for a frame? (I tried it that way and all my AIs kicked in a started killing each other during the loading screen!)

    Also, another smaller hiccup seems to occur any time I reactivate a stopped/paused behaviour. It's not quite as bad as the deserialization but still noticable. It looks like the graphs might be updating their internal references to various blackboard variables. Since I never change any blackboard data in any of my scripts I think it might be safe for me to skip this step after the first time. Assuming it is safe, where would be the best place to edit the code to allow me to avoid all that after the first initialization?
     
  2. devstudent14

    devstudent14

    Joined:
    Feb 18, 2014
    Posts:
    133
    I'm trying to import the example scenes for Node Canvas but I'm getting an error saying that DialogueTree does not contain a definition for StartDialogue. How do I fix this?
     
  3. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,087
    That's really awesome Tim!
    Thanks a lot for making those! I have updated the link in the extensions page of the website to point to your Motion Controller Vault :)


    Hey,
    Deserialization of the graph is taking place right after they are instantiated which is done in the GraphOwner's Awake function. Normally Awake will run even if a component is disabled, but in case the whole gameobject is disabled, Awake does not run until the gameobject is enabled once.

    Once thing you can do, is to set the "OnEnable" option in the GraphOwner component inspector to "Do Nothing". As such the assigned graph will not start automatically when the gameobject is enabled, but in this case you will have to manually start it by calling "StartBehaviour()" on the GraphOwner component reference in question. The graph will though still be deserialized in Awake call of the GraphOwner.
    If it helps, I could move the code from Awake into a public "Initialize" method so that it can manually be called.

    Regarding your second question, indeed some references are updated whenever the graph is started/restarted and which could be avoided to be done only once with a boolean variable. For that please take a look at Graph.cs line #555 (UpdateReferences method). This is the method you would want to avoid from being re-called and it is safe to do that as long as the blackboard reference remains the same, which is the case most of the times.

    Please let me know if that works for you, or if you need any help with making the changes (or anything else :))
    If you want so, I can make the changes and send them over to you (along with some other improvements I've made). If so, just send me PM with your email. :)
    Thanks!

    Hello,
    Sorry about that. I've just updated the examples. Please re-download the package and let me know if everything works correctly for you.
    Thanks!
     
    TeagansDad and Tryz like this.
  4. devstudent14

    devstudent14

    Joined:
    Feb 18, 2014
    Posts:
    133
    Thanks for replying :) Unfortunately this time it's saying that the namespace AI does not exist in UnityEngine.
     
  5. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,087
    Hello again,
    Please execute the command "Assets/Run API Updater..." from the Unity's top menu so that scripts are updated.
    Let me know if that works for you.
    Thanks :)
     
  6. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,087
    @mattockman
    Oh... Sorry I misunderstood your last post in thought of something different. :/
    I have attached a fix package for you here, so that you don't have to re-download the (now updated) examples package again.
    Sorry for the inconvenience.
     

    Attached Files:

    devstudent14 likes this.
  7. Sluggy

    Sluggy

    Joined:
    Nov 27, 2012
    Posts:
    960
    Yeah, after some more profiling and tracing I ended up doing exactly what you just suggested. I made a component that during awake gathers all attached graph owners and manually updates them by calling StartBehaviour().

    That seems to work but now I have another issue ;) Nested graphs. My root graph is an FSM that uses nested behaviour trees for states. It appears the only way to get them to deserialize is to actually execute the node so that CheckInstances() gets called. I tried various ways of calling CheckInstances() at different places but I always end up with deserialization errors. Any way around this?

    Also, for the record when I first instantiate the pool of objects they are in fact active and enabled until just after instantiation. I don't have your code to look at right now but I'm pretty sure it isn't getting deserialized unless its active for one frame (or StartBehaviour() is called manually). Are you sure it gets initialized in Awake and not in Start?

    I can certainly make the changes myself but if it is something you intend to integrate into the final product I'll give you my email and the asset invoice number so that I can get offical code. I don't like having to merge custom code every time an asset updates. Anyway thanks for all the help so far. Great support for a great product!
     
  8. Sluggy

    Sluggy

    Joined:
    Nov 27, 2012
    Posts:
    960
    Huzzah! I got the nested tree working! It was actually pretty simple... but I guess staying up five hours past my bedtime last night took its toll on my brain ;)

    Here is a bit of code that can be used by anyone that wants to make sure their states are fully deserialized upon awakening. Use at your own risk though! I didn't test it much so it probably isn't very robust and if your graphs aren't all that likely to hit every state in an FSM then this will waste a lot of memory unnecessarily, Also note that it does require one slight change to the file NestBTState.cs around line 115. The method CheckInstance() will have to be made public for this to work. Simply attach this component to any GameObject using a graph owner. Another handy feature of this is that you can view your object's full graph in the editor window without having to wait for it to hit each state!

    Code (CSharp):
    1.  
    2. public class PrewarmGraphs : MonoBehaviour
    3.     {
    4.         void Awake()
    5.         {
    6.             //pre-warm any attached NodeCanvas graphs
    7.             var graphs = gameObject.GetComponents<GraphOwner>();
    8.             Graph graph;
    9.             Node node;
    10.             List<Node> nodeList;
    11.          
    12.             if (graphs != null)
    13.             {
    14.                 for (int i = 0; i < graphs.Length; i++)
    15.                 {
    16.                     graph = graphs[i].graph;
    17.                     graphs[i].StartBehaviour();
    18.                     if (graph != null && graph.allNodes != null)
    19.                     {
    20.                         nodeList = graph.allNodes;
    21.                         for (int j = 0; j < nodeList.Count; j++ )
    22.                         {
    23.                             node = nodeList[j];
    24.                             NestedBTState nbts = node as NestedBTState;
    25.                             if (nbts != null) nbts.CheckInstance();
    26.                          
    27.                         }
    28.                     }
    29.                     graphs[i].StopBehaviour();
    30.                 }
    31.             }
    32.             Destroy(this);
    33.         }
    34.     }
     
  9. devstudent14

    devstudent14

    Joined:
    Feb 18, 2014
    Posts:
    133
    I think there's an issue with the scenes. Some of them are completely empty, and other scenes do not have a camera and only contain a few visible assets. I'm pretty sure I imported everything correctly. Sorry if this is just due to my own derpiness.
     
  10. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,087
    @Sluggy Hey :)
    Glad you found a way to make it work like you need. The reason why sub-graphs are not initialized along with the master/parent graph is (like you mentioned) for performance, so that they initialize only when needed instead of all of them at once. Also yes, the root graph assigned on a GraphOwner (be it Bound or Asset) is initialized in GraphOwner.Awake. I am pretty sure about that :)
    If I can help in any other way, please let me know.
    Thanks!

    @mattockman Hey,
    The example scenes package was exported from Unity 5.5 and that is probably the reason why this is happening. If you unable to upgrade to Unity 5.5 or you don't want so for any reason, please let me know and I will provide you a package for previous Unity version.
    Thanks!
     
    devstudent14 likes this.
  11. ISH_the_Creator

    ISH_the_Creator

    Joined:
    May 8, 2013
    Posts:
    165
    Are there plans or is it already a convert nodes to script ?

    I like that it works with motion controller and playmaker, only thing about playmaker i dont

    Like is the more complex you get with it the more bloated your project gets. Is this different in

    That area,

    Since my scripting still needs work i must depend on a visual scripting solution, Is NC

    That? Can a entire game be done in NC. Just seeing the options from this or a 300$ asset.

    But after seeing http://www.ghostofatale.com/ it answers most
     
    Last edited: Dec 26, 2016
  12. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,087
    Hello and thanks for your interest in NodeCanvas.
    Graphs are not converted to code/script and doing so is really outside the scope of NodeCanvas.
    You could potentially create a whole game using only NodeCanvas, but I would not recommend it due to complexity, unless of course it's a simple game. What I mean by that, is that sooner or later, writing scripts will be inevitable, but NC can interface with your scripts (basically any component code) with ease, allowing you to call functions, get/set properties/fields etc. without any problem :)

    If you have any other questions, by all means do let me know.
    Thanks again and marry Christmas!
     
  13. Zergling103

    Zergling103

    Joined:
    Aug 16, 2011
    Posts:
    392
    Hey there.

    While using NC I’ve added features and other minor improvements that I think others may find useful. I’d like them to be supported in future updates if possible.
    Do you have a git repository that I may create a branch for? Then we may discuss the changes and consider pulling them into the master branch.

    Changes include:
    Support for using Enums (of any type) instead of Strings for identifiers and tags. Includes multiple ways of searching for states from code, UI integration, 0 GC Allocation (except in initialization cases). Enums (in my opinion) are superior to strings for scripting because of their deeper integration with the programming language: They are easier to refactor and typos are caught as compiler errors, whereas with strings you need to search the project for occurances of strings and typos will silently fail.
    – Supplied the option to update graphs manually via another script as opposed to being updated via MonoManager. (This is required in cases where execution order is important and can only be resolved via execution by another script.)
    – Supplied the option to execute nested FSMs immediately upon OnEnter, instead of deferring execution to the next frame. (This is required in some cases, because the condition which triggered the state change may need to be evaluated by again nested FSMs, and the condition may change between frames, leading to bugs.)
    – Various GC allocation improvements.
    – Null handling improvements.

    I wish to keep upgrading NodeCanvas as updates are made (mainly due to performance concerns at instantiation, which I presume may be fixed in a future update), and if possible I’d like our changes to be integrated so that upgrading is smooth.

    Attached is a screenshot showing an example of the Enum integration into the UI. I’ve chosen arbitrary enums (some belonging to other assets).
     

    Attached Files:

    TeagansDad and ZiadJ like this.
  14. Seith

    Seith

    Joined:
    Nov 3, 2012
    Posts:
    755
    @nuverian Hi, I found a bug in Node Canvas which makes it impossible to zoom in the behavior editor window while in game-mode.

    If the game is not running I can zoom in/out as usual with the mousewheel but when the game is running the zoom speed seems divided by at least a hundred; it would probably take 15mn to zoom in by about 10 pixels.

    Is it a known bug? And if so, is it already fixed in the latest version?
     
  15. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,517
    @nuverian Hi. I am not sure if you remember me, but I have tried to use NC, two years ago and landed up not using it because of the number of game objects NC were producing per node in the BT. Gush,.. it's been two years! :D

    Since then , my game has got released and now I am working on my next one. And I wanted to find out if the number of gameobjects being created and present in the scene per node in BT issue has been addressed?

    It will be great to be able to come back to NC and start playing with it again and actually use it for my next game. It's been two years and a lot could have happened. And I am glad to see NC is still kicking and strong!
     
  16. Cygon4

    Cygon4

    Joined:
    Sep 17, 2012
    Posts:
    382
    Hi!

    I've made a few custom ActionTasks for my game and some of them contain string fields. Can those string fields be displayed as text areas (multiline text boxes) in the NodeCanvas inspector?

    I've tried the [MultiLine] and [TextArea(m, n)] attributes but they don't seem to have any effect.
     
  17. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,517
    Hi @nuverian. I have some serious problem with BT editor. I was trying to check for null on one of custom class object that is exposed in my another class (monobehaviour) class and now the whole BT editor as well as Unity freezes when I try to select that conditional node in the editor. When I force close Unity, it says Unity crashed.

    Unity does spit out some errors before then and they are like stack over flow error. I think the problem is happening in the editor side when it is trying to draw its property in BT editor window.

    I am unable to delete that node because it locks up Unity. Can you please check it out? I can send 3 node assets, one fsm and 2 BT.

    I was able to export the problematic BT in json and here is the node part that is causing the lockup.

    {
    "_condition": {
    "valueA": {
    "_name": ""
    },
    "valueB": {

    },
    "$type": "NodeCanvas.Tasks.Conditions.CheckVariable`1[[Pixellore.Navigation.NavNode, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]]"
    },
    "_position": {
    "x": 5657.0,
    "y": 5383.0
    },
    "$type": "NodeCanvas.BehaviourTrees.ConditionNode"
    }

    Basially I was trying to check if this particular variable (class object) in my BB was null or not. It's very weird that it only happens to this particular class. I can send you the class in question (NavNode) if you want. Let me know how I can send you.
     
    Last edited: Jan 5, 2017
  18. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,517
    Couple of things :

    1. How do you return success or failure from executing function action? Especially when it is a coroutine.

    2. for Fsm, Transition check , check after finished. How do I send event from the script that can be used by the fsm? What I mean is I did send the event, and the log does show it has sent and received it, but the transition condition is not detecting it. This may be impossible , but I suppose I can't send event from my script when it is being run by the execute function action when fsm's transition check is set to "check after finished" ?
     
  19. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,087

    Hey,
    That sounds great, thanks a lot!
    I've replied to your forum post in the NodeCanvas forums.
    Please take a look and let me know. ;)
    Thanks again.


    Hey,
    Hmm. I really don't remember experience this issue.
    What combination of NodeCanvas and Unity version are you using?
    Please let me know.
    Thanks!

    Hello again!
    Yes, I do remember you actually, even though it's been that long indeed :)
    NC has *radically* changed from version 1.x. There are no gameobjects involved at all now and everything is serialized to json (which I see you already figured that out judging from your other post), as well as of course a whole lot of other changes.


    Hmm. It looks like there is some cyclic serialization reference (aka loop) in your NavNode class. Am I correct to assume that NavNode is an object derived class that also has another serializable NavNode member field?
    Can you please send me over the reproduction case files to check this out to support@paradoxnotion.com ?
    Thanks in advance!

    1. The Execute Function action task always returns Success since there is no basis upon which a Success/Failure can be determined (unless you have some suggestion of course). You can however use the Check Function condition task, which can call a boolean function and return Success/Failure based on what the executed function returns. Let me know if that works for you (or if now).

    2. Indeed, sending an event from a function that is executed from within a state, while at the same time that state is set to Check transitions After Finish is impossible, since at the time the event is send, the state is not really finished but rather still running :)

    Cheers!


    Hey!
    Please use the [TextAreaField(float height)] attribute :)
    Let me know if that works for you.
    Cheers!
     
  20. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,517
    Hi @nuverian

    Thanks for the reply.

    Yes indeed. NavNode indeed has another public NavNode class property. Do you think making that a private will solve the problem?
     
  21. Seith

    Seith

    Joined:
    Nov 3, 2012
    Posts:
    755
    @nuverian Sorry, I should have indicated this info: I'm using NC 2.6.0 with Unity 5.4.1p1.

    It's a tricky bug because it doesn't happen all the time. Sometimes everything works as intended, but in certain circumstances the mouse wheel's "speed" gets slowed down to a crawl or altogether ignored (mouse wheel has no effect at all). Note that when it happens the mouse wheel is still recognized normally by Unity's other windows.
     
  22. ISH_the_Creator

    ISH_the_Creator

    Joined:
    May 8, 2013
    Posts:
    165
    Thanks for the reply, Since Node canvas is compatible with ootii products its safe to say the same for flow canvas?

    Also with Flow Canvas it's capable of making a game regardless of complexities as well as teach one how to code

    And understand the scripting process.

    I can't code yet but plan to code, In the production process working with Flow canvas making a 3rd person hack

    And slash with many levels, Many Boss fights and random enemies, This should not be over kill for a small team using Node Canvas and Flow Canvas because I am bought on these two

    And Slate for cut scenes.
     
  23. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,087

    Hey,
    Doing this should fix the problem, yes. Have you tried? If so, please let me know.
    In either case of course, I'd still need to fix this from meshing up in the inspector editor.
    If it's possible for you to send me the small reproduction project (or files making up for this), that would really help.
    Thanks in advance. :)

    Hey,
    No problem and sorry for the late reply myself.
    I really can't reproduce this behaviour with the NC+Unity version you mentioned (or any other version combination for that matter).
    Hmm. Just so that we rule out a few things, can you please open up GraphEditor.cs and replace both methods DoSmoothPan and DoSmoothZoom with the following code and let me know if that works (even if choppy)?
    Code (CSharp):
    1.         void DoSmoothPan(){
    2.             if (smoothPan != null){
    3.                 pan = smoothPan.Value;
    4.                 Repaint();
    5.             }
    6.         }
    7.  
    8.         void DoSmoothZoom(){
    9.             if (smoothZoomFactor != null){
    10.                 zoomFactor = smoothZoomFactor.Value;
    11.                 Repaint();
    12.             }
    13.         }

    Thanks.

    Hey,

    First of all, thanks a lot for getting the tools and I'm glad to hear they are part of your workflow! :)
    If you download the FlowCanvas-NodeCanvas extension bridge from either website (NC or FC) downloads section, among other things, it will give you the ability to make use of any NodeCanvas task (action/condition) within FlowCanvas as a node. What that means, is that you are able to use ootii's Motion Controller extension created for NodeCanvas, within FlowCanvas as well, along of course with any other extension available :)

    If you need any help or have any questions, just let me know.
    Thanks again.
     
    ISH_the_Creator likes this.
  24. ISH_the_Creator

    ISH_the_Creator

    Joined:
    May 8, 2013
    Posts:
    165

    Sweet and thanks. The unity community is among the best because of the great DEVS in it

    long live it.
     
  25. Seith

    Seith

    Joined:
    Nov 3, 2012
    Posts:
    755
    @nuverian Thank you, I did just that and I'll let you know if the bug happens again!
     
  26. username132323232

    username132323232

    Joined:
    Dec 9, 2014
    Posts:
    477
    Hi. I tried to update NodeCanvas 2.6.2 in a project that used 2.x (not sure which one). After the import, I get a lot of errors like this:
    How can this be fixed? Thanks.
     
  27. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,087
    Thanks a lot for your feedback relacon :)

    Thanks Seith. Please let me know if this happens again.

    Hey,
    Please download and import DOTween in your project.
    DOTween was included in the previous version of NodeCanvas by default, but no longer and thus it now has to be downloaded separately.
    Let me know if that works for you.
    Thanks.
     
  28. username132323232

    username132323232

    Joined:
    Dec 9, 2014
    Posts:
    477
    @nuverian Thank you for the quick response. After importing DOTween, I'm getting this error:

     
  29. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,517
    @nuverian What would be the best way to go about saving the BT states and the load them back again? Has this been discussed somewhere before? I am talking about typical save game and then load game scenario.

    At first I thought to save the current node name and try to make it jump there,... but there are more complications when the nodes are using the blackboard contents and they need to be saved.. but then the source of the content in blackboard could have come from somewhere else which is linked with other custom class etc..

    I realize this may be a much bigger topic than just about node canvas, but I would like to hear some good advice or working practice on performing save/load game involving AIs using BT such as node canvas. (especially node canvas)
     
  30. Studio-Techtrics

    Studio-Techtrics

    Joined:
    Jan 29, 2016
    Posts:
    36
    Hello!

    One thing I need to say to author.. zoom&panning functionality is a bit wonky. I remember I needed to change that part of code (zoom/cam) because it wouldn't compile so I think I commented something out.

    Another thing, probably impossible to do but still.. I wish to connect multiple nodes to one, so I don't need to copy paste nodes.. the execution could came back from where it came from :).

    Also just to give heads up, this is great plugin!
     
  31. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,087
    Hello,
    It looks like the old DOTween folder that came with the previous version of NodeCanvas is still there.
    Please find and delete the "DOTween" folder that resides under "NodeCanvas/Tasks/Actions/Tween".

    If you still encounter any problems, then I strongly suggest that you please:
    • Delete NodeCanvas folder and re-import NodeCanvas package anew.
    • Download and import NC DOTween extension package from here.
    • Download and import DOTween if not already imported.
    Let me know.
    Thank you.

    Hey,
    I think that ideally, a BT would be designed in such way as to be able to always execute the correct "route" based on the conditions it contains and the game state, which of course includes the current state of the variables of the agent.
    As such, one way would be to only store and load the blackboard variables for a game save and in most cases it should suffice.
    The blackboard variables can easily be saved to a json string simply by using Blackboard.Serialize() (which returns the json string) and then use Blackboard.Deserialize(string json) when you want to load the saved variables back.
    The json string returned by Serialize, can then be used as part of your game save for example.

    Let me know if that helps or if you want to further elaborate :)
    Thanks.

    Hello,

    Thanks. I am glad you like NodeCanvas!
    Can you please explain what seems to be wrong by the zoom/pan? Could it be due to the changes you made?
    The latest version of NC on the asset store has that compile error fixed, thus I would suggest to please update and import the latest version just in case and let me know whether or not the zoom/pan works correctly for you.

    While technically speaking, I could allow BT nodes to have multiple parents, it is something that I opted not to do so, as to keep NodeCanvas BTs more in the same design paradigm standard that most -if not all- Behaviour Trees work (in other software, articles, papers etc), where clearly a node can only have one parent. :)

    Thanks!
     
  32. username132323232

    username132323232

    Joined:
    Dec 9, 2014
    Posts:
    477
    This worked. Thanks!

     
  33. Seith

    Seith

    Joined:
    Nov 3, 2012
    Posts:
    755
    @nuverian Hi, I just upgraded to Unity 5.5.0p4 (from 5.4.1p1) and I now have the following warnings in the console:



    It seems related to the fact that now (starting from 5.5) NavMeshAgents are part of a different namespace. They're not UnityEngine.NavMeshAgent anymore but UnityEngine.AI.NavMeshAgent. Unity basically moved everything related to agents to the "AI" namespace.

    How can I fix those warnings/messages, please?

    Update 1:
    Sorry but this is actually an emergency: I get this error when starting the game:




    Update 2:
    I saw the mention about having to go to "Tools->... Update project to 2.6.2" and so I did just that. But all it did is lock Unity for 20mn and flood the console with errors and warnings. I had to kill the process when I saw CPU wasn't working on it anymore.

    More info about the errors in game mode (one for each actor):



    Back to square one. I really need your help...
     
    Last edited: Jan 16, 2017
  34. Studio-Techtrics

    Studio-Techtrics

    Joined:
    Jan 29, 2016
    Posts:
    36
    Hello!

    I will update it, hopefully it will fix it. I don't know what changes I have made out of my head, I think it was something with Vector3.SmoothDamp I think.


    Also what I mean was convert Behavior Tree to Directed Acyclic Graph, https://en.wikipedia.org/wiki/Directed_acyclic_graph. If you make it that it returns to same path that it came from, it would still have behavior (just less redundancy :) )

    Also picture for more clarity:

    But agree, BTs are usually not like that (never seen one like that) though they easily could be. With NodeCanvas it is kind of doable but quite hard, with subtrees.
     
  35. username132323232

    username132323232

    Joined:
    Dec 9, 2014
    Posts:
    477
    Sorry if this was asked before, but is there a way to automatically convert a 1.6.x FSM to 2.x? Doing that manually would be really time-consuming and prone to errors :)
     
  36. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,087
    Hey,
    Please let me know if everything is ok with zoom/pan once you update to last version.
    Yes. a directed graph is also what I understood from your post. Actually the Dialogue Trees system in NodeCanvas kind of works this way, but for the Behaviour Trees system, I'd really prefer to keep it more... "standard" :)

    Hey,
    I am sorry, but unfortunately automatically upgrading from version 1.x to 2.x is not possible in any way. I really wish there was a way, but NodeCanvas was vastly changed back when that change from 1.x to 2.x happened and it was impossible to do so. :/ Something that will never happen again in the future though.
     
  37. username132323232

    username132323232

    Joined:
    Dec 9, 2014
    Posts:
    477
    No problem :) Could you please tell me where exactly the FSM data "lives" in 1.x? I think it would be much easier to recreate it by looking it a file (text, XML; sorry, I don't know what format it's in) vs. its graph representation.
     
  38. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,087
    In version 1.x the graph data were stored/serialized in UnityObjects and with UnityObject references, thus native Unity serialization. This is also the main reason why version 2.x came to be without the ability to upgrade 1.x version graphs (because there was not a good serialization in place from which possible to update to the now used JSON serialization).
    So unfortunately I don't think there is any human readable data to look at version 1.x. Sorry :/
     
  39. chai

    chai

    Joined:
    Jun 3, 2009
    Posts:
    84
    Howdy nuverian, hope you don't mind me asking but any ETA on next version? :p
    Practically checking for updates every day, can't wait for passing values to local subtree variables, am all tingly inside in anticipation! :D
     
  40. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,087
    Hey!
    I am wrapping the new version up and it will most probably be available within this weekend :)
    Thanks!
     
  41. chai

    chai

    Joined:
    Jun 3, 2009
    Posts:
    84
    Omg omg omg! :D
     
  42. Ulven2

    Ulven2

    Joined:
    Apr 23, 2012
    Posts:
    64
    I'm wondering if anyone can help me as I can't seem to figure this out. I want to listen in on when a blackboard is getting updated (getting it's values set) to update the corresponding game UI. So I (naively) put a delegate/event in Blackboard.cs
    public delegate void ValueChangedAction();
    public event ValueChangedAction onValueChanged;

    and then call it in SetValue

    public Variable SetValue(string name, object value){
    if (onValueChanged != null){
    onValueChanged();
    }
    return _blackboard.SetValue(name, value);
    }

    This works fine for any SetValue call I do, but when the value of a variable in the blackboard is changed from within for example a node that uses BBParameter, this doesn't get called and I can't quite work out where it's being set. What's the right way of doing this?
     
  43. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,087
    Hey,
    There is actually already an onValueChanged event you can use for when a variable changes, but the difference here, is that this event exists in the variable itself rather than the blackboard.
    Here is a code example for you:
    Code (CSharp):
    1. public class Example : MonoBehaviour {
    2.  
    3.     public Blackboard blackboard;
    4.  
    5.     void OnEnable(){
    6.         var theVariable = blackboard.GetVariable("MyVariableName");
    7.         theVariable.onValueChanged += (name, value)=>{ Debug.Log(string.Format("Variable {0} Set to {1}", name, value)); };
    8.     }
    9. }
    For your information, the reason why your event does not work, is because BBParameters bind the Variables with a direct delegate call for performance and thus SetValue is not called at all when a BBParameter sets linked variable (neither does GetValue for get).

    Let me know if the above works for you.
    Thanks :)
     
  44. zenGarden

    zenGarden

    Joined:
    Mar 30, 2013
    Posts:
    4,538
    I created a new task under the right folder 'Movement"

    Code (CSharp):
    1. using NodeCanvas.Framework;
    2. using ParadoxNotion.Design;
    3. using UnityEngine;
    4.  
    5.  
    6. namespace NodeCanvas.Tasks.Actions{
    7.  
    8.     [Name("Move To Target")]
    9.     [Category("Movement")]
    10.     public class StopMove : ActionTask<NavMeshAgent> {
    11.  
    12.         [RequiredField]
    13.    
    14.    
    15.  
    16.         private Vector3? lastRequest;
    17.  
    18.         protected override string info{
    19.             get {return "Stop Move " ;}
    20.         }
    21.  
    22.         protected override void OnExecute(){
    23.  
    24.             agent.Stop ();
    25.                 EndAction(true);
    26.                 return;
    27.         }
    28.  
    29.         protected override void OnUpdate(){
    30.            
    31.         }
    32.         protected override void OnStop(){
    33.             if (lastRequest != null && agent.gameObject.activeSelf){
    34.                 agent.ResetPath();
    35.             }
    36.             lastRequest = null;
    37.         }
    38.  
    39.         protected override void OnPause(){
    40.             OnStop();
    41.         }
    42.  
    43.        
    44.     }
    45. }
    It compiles , but i dont' see the new task when i try to find it in the editor task selection ?
     
  45. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,087
    Hey,
    That is because you've set the display name of the task to "Move To Target" using the [Name] attribute and there is already one existing with the same name :)
    Please either remove the [Name] attribute, or change the display name to be something different. You don't really need the name attribute if you just want the display name to be the same as the type name by the way (in this case "Stop Move" for example)
    Also, custom tasks can exist in any folder you like and is not mandatory to be in any specific folder. As a matter of fact it's better not to place your custom tasks in the NodeCanvas folder/subfolders, so that you can update safely. :)

    Let me know if that works for you.
    Thanks!
     
    zenGarden likes this.
  46. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,517
    Hi @nuverian

    When you deserialize blackboad back from json, is there any way to preserve the object's blackboard content and only overwrite the data for the one that is already exist in the blackboard?

    So for example, if I saved serialized blackboard and then later I added a new string variable to the blackboard. And when I deserialize old blackboard data back, it removes the variable I have added later.

    I think there should be option to both do AND , OR operations.

    Is this possible? :( I think this is crucial. Otherwise you need to define blackboard entries complete 100% from the beginning which isn't possible to do most of the time during development.

    --- Edit ---

    I have tried to modify the code to see if it can work like this, any feedback? Will this work?

    Code (CSharp):
    1.  
    2. public bool Deserialize(string json, bool removeNotExist = true)
    3. {
    4.             var bb = JSONSerializer.Deserialize<BlackboardSource>(json, _objectReferences);
    5.             if (bb == null){
    6.                 return false;
    7.             }
    8.  
    9.             foreach (var pair in bb.variables){
    10.                 if (_blackboard.variables.ContainsKey(pair.Key)){
    11.                     _blackboard.SetValue(pair.Key, pair.Value.value);
    12.                 } else {
    13.                     _blackboard.variables[pair.Key] = pair.Value;
    14.                 }
    15.             }
    16.  
    17.             if (removeNotExist)
    18.             {
    19.                 var keys = new List<string>(_blackboard.variables.Keys);
    20.                 foreach (string key in keys)
    21.                 {
    22.                     if (!bb.variables.ContainsKey(key))
    23.                     {
    24.                         _blackboard.variables.Remove(key);
    25.                     }
    26.                 }
    27.             }
    28.          
    29.             _blackboard.InitializePropertiesBinding(propertiesBindTarget, true);
    30.             return true;
    31.  }
     
    Last edited: Mar 3, 2017
  47. WookieWookie

    WookieWookie

    Joined:
    Mar 10, 2014
    Posts:
    34
    I cannot find this script anywhere in my project. Where is it and what exactly is it called?
     
  48. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,087

    Hey,
    Yes, this modification will definitely work just fine and achieve what you are after.
    I will add this option in the next release as well (makes sense to exist as an option :) )
    Thanks!


    Hello,
    This feature (from version 1.5 ) has been completely removed from NodeCanvas and replaced with the ability of variables to be data bound to properties which is much more flexible and performant. With this data binding feature, a very similar result can be achieved just by writing a simple custom script.

    For example, you can create such a script like this, where you can add as many properties that simply get/set the relevant animator parameters. You can if you want do this for all your animator parameters, or just some of them. In this example, I just did it for two parameters, speed and direction.
    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class AnimatorParameters : MonoBehaviour{
    4.  
    5.     private Animator _animator;
    6.     private Animator animator{
    7.         get {return _animator != null? _animator : _animator = GetComponent<Animator>();}
    8.     }
    9.  
    10.     public float speed{
    11.         get {return animator.GetFloat("speed");}
    12.         set {animator.SetFloat("speed", value);}
    13.     }
    14.  
    15.     public float direction{
    16.         get {return animator.GetFloat("direction");}
    17.         set {animator.SetFloat("direction", value);}
    18.     }
    19.  
    20.     //etc...
    21. }
    Then you can create a "Bound Variable" in the blackboard, for each of those properties through the button "Add Variable" and selecting "Bound Self/Properties/AnimatorParameters/...".
    Doing so, you will end up with one variable bound for each property.
    PropertyBinding.png

    As a final result, when you get the speed variable, the animator speed parameter value will be returned, and when you set the speed variable, the animator speed parameter will be set.

    Please let me know if that helps, or if you need any further explanation.
    Thanks!
     
  49. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,517
    Hi @nuverian

    After adding custom class object by using preferred type editor to my black board, I have changed name space of some of my classes. Now the blackboard has the value part of that class as red color indicating that it can't find it. And it does seem to try and fall back by searching. Which is ok for me, but there are no ways for me to change that class variable so that it is pointing to the right class. It does not even let me delete it. I can't move that variable around neither. What can I do? Do I have to manually go through the saved json string on the blackboard component to fix this issue?

    let me know!
     
  50. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,087
    Hey,
    The variable with the missing type, should be able to be deleted.
    Are you not seeing an "X" button on the right side of the variable?
    MissingVariableType.png

    Thanks.