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. Danirey

    Danirey

    Joined:
    Apr 3, 2013
    Posts:
    548
    I'm confused too :D

    The exact example is an action that chooses based on a probability a gameobject(body part) from a list in a character master script. Then i need to asign the value(the gameobject of the part choosed) to a variable already created in the BB so in other node of the BT could be used.

    I've everything right, except setting the value to the variable. If i set A.value(the variable i will use later on in the BT) = b.value( the private var with the selected body part gameObject), when i check A in the blackboard it has the same value before the operation.

    I'm going crazy....

    It will be better to sleep and rethink this basic question tomorrow! I'm really a zombie now.

    Thanks nuverian!
     
  2. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,087
    It seems pretty straight forward :) Maybe you miss something or re-setting the a.value somewhere?
    Send me the task if you want me to take a look if everything still doesn't work for you tomorrow, or any time you wish.

    Indeed working late doens't help. I know the feeling :)
     
  3. msl_manni

    msl_manni

    Joined:
    Jul 5, 2011
    Posts:
    272
    Bug Report : Latest Update

    Imported NC into new project. The Action List is not working as intended. Cant set actions if multiple actions are there in action list. The Action List is broken.

    Due to broken Action List - FSM is not working properly.
     
    Last edited: Jul 1, 2014
  4. atmuc

    atmuc

    Joined:
    Feb 28, 2011
    Posts:
    1,151
    How i going Windows Store Apps and Windows Phone 8 integration? :) uSequencer asset had the same problem and they did it within 3 days :)
     
  5. Danirey

    Danirey

    Joined:
    Apr 3, 2013
    Posts:
    548
    Thanks man!

    i'm at work right now, but as soon as i can, i'll try again. If still not working, i'll send you the Task.


    Cheers!


    EDIT:

    Hi Nuverian!

    Solved. Of course today i can see the things like a real person and not like a zombie!

    All working fine!

    Thanks again!
     
    Last edited: Jul 1, 2014
  6. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,087
    I'm not sure what you mean. You press the 'eye' icon in the list to select the action to set.
    What's the problem with the FSM?

    I didn't have much time to work on it up until very recently. I can send you a beta version if you want to test it out. PM me an email to send it :)

    Glad to know everything is working as expected :)

    Cheers
     
  7. Danirey

    Danirey

    Joined:
    Apr 3, 2013
    Posts:
    548
    Dear nuverian ;)

    I'm here again, but now with good and bad news. The good is that i'm starting to understand all this stuff and making characters almost think like an ameba. The bad news: When i open Unity after saving all and applying prefabs etc... All the custom nodes are gone in all BT's.

    Here are some screens showing before and after of the simplest BT i have. The other two are more complex but the problem is the same.

    COVER_BT.jpg
    COVER_BT_MISSING.jpg
    Please, let me know wht do you think. One of the scripts is the overlapSphere example you posted days ago.

    Cheers!
     
  8. msl_manni

    msl_manni

    Joined:
    Jul 5, 2011
    Posts:
    272
    I did not knew that now you have to press the 'eye' icon only to select the action to set. :rolleyes: I was trying to press the text area to select, it worked earlier. :oops:
     
  9. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,087
    Hey,
    Did you probably renamed you classes at a later point? Also make sure that your class names are the same with the script names. I will add a safety check for that.

    Yeah, that has changed from when the reorderable lists were added. You are able to reorded the list by clicking and draggin the name itself, thats why the inspection is done with the 'eye' icon.
     
  10. msl_manni

    msl_manni

    Joined:
    Jul 5, 2011
    Posts:
    272

    I don't know how to assign or check values for these - BBMaterial, BBTexture2D, BBRigidbody etc. I suppose I have to write action and condition code to use it in NC. Or is there a Generic way to assign value and also to check values of these new BB variables.


    Again missing action-condition code on how to use this in NC.

    1. What is the proper way to create our own class list.
    2. Assign value to class var in action node to specific index of the list etc. eg. Hero[5].Health -= 5;
    3. Check value of a specific index of list var. eg. if ( Hero[1].Level == 5 ) Hero[1].MP = 50;


    I cant seem to figure out the above, so please elaborate the above.
    Thanks,
    MSL.
     
  11. Danirey

    Danirey

    Joined:
    Apr 3, 2013
    Posts:
    548
    :oops: Oh for gods sake!

    Thank you nuverian!. I've a discrepance between one class name and the script name.

    This is like black magic to me sometimes...o_O

    :DNice that it was my fault. And something so easy to fix. You really have some experience with this;)

    Thanks!
     
    Last edited: Jul 2, 2014
  12. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,087
    There is not a dedicated get/set for each and every possible blackboard variable data type, cause this will really flood up the task lists. I will see to creating a generic one if possible. The main purpose of those new BBVariables is that you can use them in your own tasks to allow a selection in the task editor for those types if you need to create some relevant tasks that have to do with any of those types.
    Again, those BBVariables are there mostly for helping in editor selection and allow some flexibility. If you want to read/write to the blackboard directly through code you can just call GetDataValue<Material>("myMaterial") on the blackboard for example. If you wanted a visual selection in the editor you can use a BBMaterial.

    Regarding the example Hero custom variable type which derives from System.Object. If you are going to create custom variable types, then you most probably are going to create custom tasks as well to make use of those variables.
    Again you can read/write those directly from the blackboard by GetDataValue<Hero>("myHero") or create a BBHero variable to do so visualy in the editor. Take a look at the new doc page here.

    Regarding creating a List<Hero> the workflow is the same:

    Suppose we have this type:
    Hero.cs
    Code (CSharp):
    1. [System.Serializable]
    2. public class Hero{
    3.     public string name;
    4.     public int level;
    5. }
    We create a variable data having a List<Hero>:
    HeroListData.cs
    Code (CSharp):
    1. using System.Collections.Generic;
    2. using NodeCanvas.Variables;
    3.  
    4. public class HeroListData : VariableData {
    5.     public List<Hero> value = new List<Hero>();
    6. }
    We can already do something like this from within a task or anywhere if we have a blackboard reference:
    Code (CSharp):
    1.  
    2. var heroes = blackboard.GetDataValue<List<Hero>>("heroes");
    3. heroes[2].level ++;
    Optionaly you can create a BBHeroList to show a drop down selection in editor instead of hardcoding it as explained here:
    BBHeroList.cs
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections.Generic;
    3. using NodeCanvas.Variables;
    4.  
    5. [System.Serializable]
    6. public class BBHeroList : BBVariable{
    7.  
    8.     [SerializeField]
    9.     private List<Hero> _value = new List<Hero>();
    10.     public List<Hero> value{
    11.         get {return useBlackboard? Read<List<Hero>>() : _value ;}
    12.         set {if (useBlackboard) Write(value); else _value = value;}
    13.     }
    14. }
    So now you can use that BBHeroList instead likeso:
    IncreaseHeroLevel.cs
    Code (CSharp):
    1. public class IncreaseHeroLevel : ActionTask {
    2.  
    3.     public BBHeroList heroes;
    4.  
    5.     protected override void OnExecute(){
    6.         heroes.value[2].level ++;
    7.     }
    8. }

    Creating custom variable types are very specific to your game and as such the tasks using them will also be specific to your game.
    I hope this helps.


    Glad to know it worked fine :)
    Thanks!
     
  13. msl_manni

    msl_manni

    Joined:
    Jul 5, 2011
    Posts:
    272
    Thanks for explanation. I know that it would be a herculean task to write get/set for every type of variables. It would be Great if you can find solution for Generic getter/setter. :D

    I will write code for my specific needs for now, as I would be using only a few of these. :)

    And thanks for the code. :)
     
  14. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,087
  15. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,087
    The next version is supporting Windows Phone 8 and Windows Store Apps, out of the box without extra steps.
    Also thanks to @atmuc

    So that sums it up to all platforms are now being supported :)
     
  16. Danirey

    Danirey

    Joined:
    Apr 3, 2013
    Posts:
    548
    Hi nuverian,

    Thanks for the updated documentation! It really helps a lot.

    I've a new question:

    Is it possible to make combinations of conditions in the FSM transitions? Like if a=1 and b=2 then go to some state, but if is only a=1 go to another one different.

    I'm thinking in using a condition list and inside other condition lists grouping the different convinations setting them to all true. Is this the way?

    Cheers!
     
  17. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,087
    Hey,

    Why not create 2 different transitions likeso:
    The first transitions having a codition list with a=1, b=2 and set it to "All True Required".
    The second transition having a=1.

    Then you could prioratize the transition checks by reordering them.

    I asume Im missing somethiing in what you are after? :)
     
  18. Danirey

    Danirey

    Joined:
    Apr 3, 2013
    Posts:
    548
    No! It is exactly what i did! Thanks! I wasn't sure.

    One more question, how can i stop start FSM from a script outside nodecanvas?
     
  19. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,087
    Oh, alright :)
    Well, that's the way to go about it.

    You can control the behaviour/FSM from the within the FSMOwner. For example (JS ;)):
    Code (JavaScript):
    1. #pragma strict
    2.  
    3. class Example extends MonoBehaviour{
    4.  
    5.     private var owner : FSMOwner;
    6.  
    7.     function Awake () {
    8.         owner = GetComponent.<FSMOwner>();
    9.     }
    10.  
    11.     function Update () {
    12.  
    13.         if (Input.GetKeyDown(KeyCode.Alpha1))
    14.             owner.StopBehaviour();
    15.  
    16.         if (Input.GetKeyDown(KeyCode.Alpha2))
    17.             owner.StartBehaviour();
    18.     }
    19. }
    There lot more you can do of course. Take a look here.
     
  20. Danirey

    Danirey

    Joined:
    Apr 3, 2013
    Posts:
    548
    :D

    THANKS!

    Working again!

    I'll show you soon a little video of what i'm getting right now.
     
  21. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,087
    Great! Please do :)
     
  22. Danirey

    Danirey

    Joined:
    Apr 3, 2013
    Posts:
    548
    Ok, i've talked too much:oops:

    It forces me to declare "NodeCanvas.StateMachines.FSMOwner" instead of FSMOwner only as in your example, and then for StartBehaviour ,pause or stop says "'StopBehaviour' is not a member of 'NodeCanvas.StateMachines.FSMOwner'. "

    Maybe i've moved something in a wrong folder? Until now all actions with JS worked fine.

    Any idea?(I'm using your sample code as you posted)
     
  23. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,087
    Hey, sorry for late reply.

    Considering you have moved folders into the Plugins folder, add:
    import NodeCanvas.StateMachines;
    on the top, which is the namespace. Each system is in it's own namespace.

    Regarding StartBehaviour, make sure you have updated to the new version. If you dont want to update for any reason, use StartGraph, StopGraph, Pausegraph etc.
    There was a slight name change in the latest version.

    Let me know
     
  24. Danirey

    Danirey

    Joined:
    Apr 3, 2013
    Posts:
    548
    Hi, don't worry.;)

    I'll try it later. Thanks and sorry for for all the noob questions:(. I'm nota an expert scripter at all. But with all this of course i'm learning tons of stuff.

    Oh, and i have to say that you have saved my project. I just redo the character controller system from scrach , because before i have the states by code and i get staked between hundreds of variables and scripts sharing them. Now with nodecanvas i 've the core control working in a few days and only adding some custom actions and conditions. Now is cleaner, more efficient and bug safe(for now) :cool:

    So, thank you nuverian!
    I want to post a video ASAP, to show you and to know what do you think about it.

    Cheers!
     
  25. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,087
    Hey, thanks for the positive feedback :). I'm very glad that you found a good use for NC in your game.
    Your are also very welcome.

    Cheers! :)
     
  26. Danirey

    Danirey

    Joined:
    Apr 3, 2013
    Posts:
    548
    OK! Nuverian! No problem! :D

    But you will not get rid of me so easily, because i've new questions for you. now i've to get access to some blackboard variables form outside of nodeCanvas. i get the Blacboard component from the actual character or enemy or whatever, but how can i get or set these values? i've seen the documentation but i don't get it.

    Regardig to the previous problem, i had both problems, the namespace import and the previous version of NC. Now it is all fixed and continuing to the next unknown pain ;)

    Cheers!
     
  27. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,087
    Hello :)

    Suppose you have a game object variable on the blackboard named "myObject", you get that gameobject by using the generic function GetDataValue:
    blackboard.GetDataValue<GameObject>("myObject");
    This will return the value of a variable named myObject which is also of type GameObject.

    To set that variable:
    blackboard.SetDataValue("myObject", player.gameObject)
    This will set a variable named myObject to the new value provided. If a variable of that value type exists it will set it, otherwise a new variable with that name will be created dynamicaly.

    Notice that in JS the syntax for generics is a bit different. You need a dot before the < :
    blackboard.GetDataValue.<GameObject>("myObject);

     
  28. Danirey

    Danirey

    Joined:
    Apr 3, 2013
    Posts:
    548
    Something like this?

    sol.GetComponent(Blackboard).SetDataValue(“selected”, false);

    :oops:
     
  29. Danirey

    Danirey

    Joined:
    Apr 3, 2013
    Posts:
    548
    And right now i've jest updated NC to the latest version, and without changing anything from the previous working test comes to me this error:

    NullReferenceException: Object reference not set to an instance of an object
    NodeCanvas.StateMachines.FSM.OnGraphUpdate () (at Assets/Plugins/NodeCanvas/Systems/FSM/FSM.cs:53)
    NodeCanvas.MonoManager.Update () (at
    Assets/Plugins/NodeCanvas/Core/Other/MonoManager.cs:58)

    This error corresponding to this line inside OnGraphUpdate() function

    currentState.OnUpdate();



    Any idea?

    Thanks
     
    Last edited: Jul 6, 2014
  30. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,087
    Im not really sure what you are asking here :)
    The GetComponent returns a Component type. You either need to cast it to Blackboard or use the generic GetComponent:
    sol.GetComponent.<Blackboard>().SetDataValue("selected", false);

    That's it to set a boolean variable on the blackboard named "selected" to false.


    Did you remove the old NodeCanvas folder and reimport anew? Please always do so. Once you do reload your scene
     
  31. Danirey

    Danirey

    Joined:
    Apr 3, 2013
    Posts:
    548
    Ok!

    ! All solved... Again:rolleyes:


    Thanks as always!
     
  32. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,087
    You are welcome :)
    Glad to be of help
     
  33. Danirey

    Danirey

    Joined:
    Apr 3, 2013
    Posts:
    548
    Well, another day, another question. :)

    How can i add, if possible, a list of actions to be executed when a state goes to OnExit? Lets say i want to reset a list of Variables only when the idle state is exiting, because some of them are in use inside the nested BT.

    if there is no way to do this, it will force me to check the conditions that allow to move to other states inside the BT.

    i'm thinking….which is not always a good thing :p

    Cheers
     
  34. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,087
    hey again :)

    The Action State doesn't have a way of running another list of actions when it Exits and its weird that you came of need it :) . OnExit, each action in the list that is still running is stoped. You could write a custom action that OnStop it does what you want it to do and add it to the list of that Idle state as an alternative.

    Another alternative would be to create your own custom state node if that state is kind of special and handle everything in code.
     
  35. Danirey

    Danirey

    Joined:
    Apr 3, 2013
    Posts:
    548
    Ok, thanks.

    I'll find a way. ;)
     
  36. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,087
    It's the time of that new submited version again :) v1.5.2
    Here are the new/changed stuff:

    • New Looks!
    • Windows Phone 8 & Store Apps support
    • Conditional Connections for Behaviour Trees have been deprecated(existing connections will work as normal, but new connections will no longer have a condition)
    • When deleting a node with 1 parent and 1 child, parent and child will automaticaly be re-connected.
    • Removed the running time UI from State nodes.
    • Removed the ID UI from Dialogue nodes.
    • Improved Grid Snapping, to take place while panning the node as well(...)
    • Added Option to display only the task name instead of the full summary info.
    • NC Menu moved under Window/NodeCanvas (required).
    • Added a menu item for creating Tasks easier.
    • The SendMessage Task can now also send any blackboard variable as an argument.
    • Editor is now even more faster, processing only the visible nodes as well.
    • Node Help information was cleaned up
    • FSMStates will now call OnStateEnter, OnStateUpdate and OnStateExit with an IState argument, on any MonoBehaviour on the agent that has such a method.
    • Fixed a BT Parallel bug.

    ...The new looks...

    BT.png

    FSM.png
    Version is submited and pending review...

    Cheers!
     
  37. msl_manni

    msl_manni

    Joined:
    Jul 5, 2011
    Posts:
    272
    Waiting to use the above. I suppose you have documented how to use the above, somewhere. :rolleyes:
     
  38. tomi-trescak

    tomi-trescak

    Joined:
    Jul 31, 2013
    Posts:
    78
    Hey, Nuverian, you made it to the first couple of scientific publications ;) I'll send you links when they will be published online. I can send you a link to the camera ready of the demo paper: http://staff.scm.uws.edu.au/~anton/Publications/SPUHH_2014.pdf
    It will be presented in the Social Simulation Conference in Barcelona.
     
  39. desyashasyi

    desyashasyi

    Joined:
    Nov 22, 2012
    Posts:
    73

    Woow... it is great. I am working in educational research using node canvas and I consider to publish it in a manuscript. :)
     
    Last edited: Jul 10, 2014
  40. desyashasyi

    desyashasyi

    Joined:
    Nov 22, 2012
    Posts:
    73
    Hii... Nuverian,
    I am not success using your snippet for NGUI. Never mind, I will try later. However, i found some time consuming working with actions. Some time i want to disable an action attached into a node. Like in Playmaker, I can check or uncheck an action. Is it easy to modify Nodecanvas script to achieve this purpose?
     
  41. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,087
    Hey, thats great! I'm very glad :)
    That was a very nice read and I especialy liked the goal oriented planning, something that I'd have thoughts to implement in NC as well. It seems like a very interesting project you have there!

    The strange coincidence is that I have done some research on sumerians and totaly love their culture and especialy their gods Anunnaki :)

    Thanks a lot for sharing and please do share the rest when available.
    Cheers!

    Hello,
    I can add a Task disabled/enabled option similar to playmaker in the next version.
    By the way right now you can disable a BT node as a whole, by selecting it's incomming connection and checking 'Disable Connection' :)
     
  42. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,087
    Im updating the documentation now :)
     
  43. desyashasyi

    desyashasyi

    Joined:
    Nov 22, 2012
    Posts:
    73
    Yes... Thank you. But for your suggestion to disable connection, is it effect for all Node? How about only disable one actions in a node containing action list?, for example, if a node contains three actions, and i just want to disable one/two action. Currently, if i want to disable such action, i should delete this action. Then i should add same action if i want to enable it. Thanks for next update planning.
     
  44. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,087
    Yes, I suggested the disable connection as a possible alternative for now. It disables the whole node :)
    It's centainly not the same as disabling a specific action in a list, thus I will add that option in next version.
    You are welcome :)


    ----
    To everyone, the new version 1.5.2 is live on the asset store :)
     
  45. msl_manni

    msl_manni

    Joined:
    Jul 5, 2011
    Posts:
    272

    Just make duplicate of that node and delete the actions which you dont want from the duplicate node. Or add new actions to either Nodes. Now link to either node you want to test. Only linked nodes connected to the main graph are evaluated. I duplicate as many as I need and only link the one to the main graph, which I want to test. I sometime keep the unlinked node in the graph to keep it as a reference of an alternate logic.
     
  46. msl_manni

    msl_manni

    Joined:
    Jul 5, 2011
    Posts:
    272

    Please give an example graph on how to use this? Cant figure out how to set it up.
     
  47. Danirey

    Danirey

    Joined:
    Apr 3, 2013
    Posts:
    548
    list.jpg

    Here is one BT i'm using. I posted an isue with it but was my fault. So since this is solved i deleted the post. I post this Bt because maybe you could tell me what do you think, and if this could be the way to go. ;) it works at least!

    Thanks!
     
    Last edited: Jul 13, 2014
  48. Danirey

    Danirey

    Joined:
    Apr 3, 2013
    Posts:
    548
    OK!, i don't know whats going on, but now it works.(I miss something in somewhere for sure)

    Here are some videos working only with nodecanvas. Player controls included. Thanks nuverian. ;)





    Cheers!
     
  49. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,087
    Hey,
    All states will callback on the the agent's monobehaviours as long as you have the required methods. For example, place this on the agent (FSMOwner):
    Code (CSharp):
    1. using UnityEngine;
    2. using NodeCanvas.StateMachines;
    3. public class Example : MonoBehaviour {
    4.     public void OnStateEnter(IState state){
    5.         Debug.Log(state.Name + " ENTERED");
    6.     }
    7.     public void OnStateUpdate(IState state){
    8.         Debug.Log(state.Name + " UPDATING");
    9.     }
    10.     public void OnStateExit(IState state){
    11.         Debug.Log(state.Name + " EXITED");
    12.     }
    13. }
    The IState interface right now holds the name, elapsedTime and the FSM in which it lives in. It's also included in the docs here.
    There is no special setup from the FSM part.

    Let me know if you have any questions :)

    Hey. You definetely got the hang of it! :) I like your tree considering you went with creating small reusable task approach instead of script controlling. I have a few remarks if you like:

    - Instead of using many bools for your current state, you could use a single string and set/check that string. It will save you some sanity :)
    - Just in case you don't know, the Iterrator can be set to exit on First Success. So as soon as the conditions of your accessor beneath it are met and it return success, the itterator will return success withoung going over up to the last index of the list.
    - You could use "Referenced Duplicated" Action nodes so that you don't have to re-do the same action if they are exactly alike, thus changing one will chagne the other. They will be 'mirrored'. (right click 'Duplicate by reference'). In next version this will also be possible for Interruptors and Accessors
    - You can press ALT+Q to scale down all nodes to minimum size (unless you have them scaled on purpose)

    By the way, you should also update to latest version for a lot of reasons :p (backup and reimport package anew)

    Thanks a lot for sharing the videos! Im very glad you are making progress on your project. Looks like it's going to be cool :)
     
  50. Danirey

    Danirey

    Joined:
    Apr 3, 2013
    Posts:
    548
    Thanks! :D

    I'll make use of your tips.

    Awesome plugin! Thanks a lot!