Modular Design

FlowCanvas Forums Support Modular Design

Tagged: , ,

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1163
    stuffses
    Participant

    I’m using FlowCanvas for AI in my game, and it’s working very well for that. However it gets a bit tricky when I want to give characters modular behaviour using FlowCanvas.

    This could be done pretty easily if there was a way to swap out Macros at runtime. A character might have an “idle behaviour” Macro that could be swapped between “Wander” and “Follow Waypoints” depending on the situation. If Macros could be set in a Blackboard Variable and used on the graph, that would be perfect.

    Is there any way to achieve this currently? Right now I’m just using big switch statements all over the canvas, but it’s pretty messy compared to a modular macro system.

    #1164
    stuffses
    Participant

    I ended up implementing Modular Macros myself, although I’m not very proud of the code. It’s a janky mess and I’m not even sure how it works, but hey it gets the job done for now!

    Here’s the code for my Modular Macro Node:

    The script will require some minor changes to the parent class, MacroNodeWrapper. I think it’s just marking some methods as virtual.

    To use it, place the above node on your blackboard, and in the first “Macro” slot, provide it with the “Interface” macro. This “interface” Macro works much like a C# interface, in that it only defines the functions (or in this case, flow and value nodes for the macro) and should have no actual logic inside.

    Once you’ve set the interface macro, refresh the ports.

    To load modular macros, duplicate your interface macro and add logic to those new macros. You can then provide those new macros to the Modular Macro Node with a Blackboard variable.

    #1165
    Gavalakis
    Keymaster

    Hello and happy new year!

    The problem with having macros being modular is (as you may have noticed) that since each macro can have different ports registered, unless the names of the ports remain the same, links will become broken in runtime when/if the macro change to one that does not have the same ports as the one assigned in edit time.

    In my opinion, a better way to make a more modular design, would be to create an abstract monobehaviour class (eg “Character”) along with abstract methods of what Characters can do, as well as character derived classes along with their implementations and finally have those methods called from within a flowscript. For example:

    The Orc script is then attached on the “self” gameobject, but from within a flowscript the base definition of the method DoSomething() is used. As such, each gameobject with a Character derived class will use it’s own implementation of DoSomething().
    AbstractCall

    Please let me know if that makes sense or if you need further explanation.
    Thanks!

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

    Attachments:
    You must be logged in to view attached files.
    #1167
    stuffses
    Participant

    Thanks for the response. That’s certainly a much more elegant solution to the problem, I think I’ll be using it a lot!

    I can see why modular macros are tricky. Still it would be nice to have some clean way to have modular FlowScript.

    #1168
    Gavalakis
    Keymaster

    Hey,

    Sorry for the late reply and I am glad you found this solution useful.
    As for modular flowscripts other than this, another way would be to use Blackboard Variables, but I can see what you are after here 🙂
    I will take a look at this regard and see what can be done.
    One possible way I can think of is the ability to create “abstract macros” where one can only define the inputs/outputs and then create derived macros of abstract macros where one defines the only contents/nodes (with inputs/outputs being fixed by the abstract parent).
    I can’t tell for sure if that will work though right now, but I will take a look at this :).

    Thank you.

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

    #1169
    stuffses
    Participant

    Yeah, some sort of abstract Macro is exactly what I’m thinking of.

    My code above basically does that, although it’s horribly hacky and isn’t very reliable. Seems to break when you have more than one on a blackboard at the same time…

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.