Reply To: Demo & redundancy

NodeCanvas Forums General Discussion Demo & redundancy Reply To: Demo & redundancy

#9045
Gavalakis
Keymaster

Hello,

NC does not support polymorphism in the sense that you describe it and to be honest I don’t personaly know of any behaviour tree system that does that. The way this works with behaviours tree, or to be more precise in NodeCanvas is different. There are different ways to alter the functionality per type that come into mind. For that let’s take an example.

You have an abstract class Unit, and 2 subclasses: Fighter and Archer.
These are normal MonoBehaviour classes that you add on your game objects.
The abstract class Unit has abstract methods or even properties, like for example: Attack, Health, Speed etc

You create a behaviour tree that defines the global behaviour of a Unit. As such you attach that behaviour tree on each game object that has a Unit subclass.
Now within that behaviour tree you make calls, sets and checks on that Unit type (using Script Control tasks) which allow NC to “interface” with your classes.
As such, the Fighter will Attack differently than the Archer, since each Unit defines it’s own method for Attack.
(this can also work with interfaces instead of abstract classes if you want to)

Furthermore, the Blackboard Variables (which can be used to parametrize behaviour tasks amongst other things), are not coupled to the behaviour tree, but rather with the agent. As such the same created behaviour tree, can be further parametrized per the type using it, by altering the variables.

Using blackboard variables versus your own properties within a class and interfacing with them, is more or less the same thing. In both cases you can use them to parametrize the attached behaviour tasks and thus the behaviour as a whole, by reading, setting and checking values.

Another thing at your disposal is SubTrees. So you create the master behaviour tree for all units and when a unit is about to attack, define that Attack as a SubTree. Then depending on the Unit type (Fighter, Archer etc), each one may use a different whole SubTree for Attacking and thus differentiate their behaviour. (currently assigning subtrees can only be done through code, but it will be possible through UI in the next version).

So as you can see, behaviour trees (at least in NC) have lot of ways to be parametrized based on the sub type using them 🙂
My personal preference is the first in case you are into and prefer coding your behaviour pieces. The more you want to rely on the behaviour tree system, the more you lean towards using SubTrees instead.

Finaly, as for a demo version, if you still have doubts :), I could make a quick and dirty .DLL version for you to try it out.

Cheers!

Join us on Discord: https://discord.gg/97q2Rjh