FlowCanvas Forums › Support › Best practice for similar method as class vars and instance vars?
Having come from Bolt 2 that uses a class-like system for it’s variables (similar to c#) I’m trying to find the best approach to setting my vars. There’s two ways of setting up a graph, bound and asset, and there’s two ways of setting up a variable, object or graph, and any of these can be on a prefab. If I were to, say, have an enemy that I know always wants to move at the same speed, all of those enemies would have a speed float that’s the same. If I’m working on finding the right speed whilst testing, I’d want to be able to change the speed var on the enemy object while in playmode. Somewhere down the line, I may want to adjust this speed setting once again, after all of my enemies have been placed, and they’d all need changing.
I think can only change graph variables on the graph asset, which rules out being able to fine-tune the enemy in Play mode, and if the enemy uses object variables, that means only one of the instances will be affected by the change to the speed variable.
Usually, the c# script would have a default variable, and all of the objects using this script would use this variable unless the box was ticked and the individual instance’s variable was changed. What’s the best working practice here to emulate a c# class style of working?
Hello there,
Once in playmode, all agents (FlowScriptController) create an instance of the graph being used. As such, in playmode, each graph has it’s own instance of blackboard variables as well and thus changing the variable value in one of the instanced prefabs of your character will naturally not change the variable value on all other instances but rather only to that instance.
So regarding testing and finding the correct speed value in your example, it can only be done so in one instance at a time in playmode and as soon as the correct value is found and exit playmode, the change the characters prefab speed variable to that desired speed value. The next time you enter playmode and an instance of that prefab is made, all instances will share the same speed variable value initially.
Join us on Discord: https://discord.gg/97q2Rjh
Hello there, Once in playmode, all agents (FlowScriptController) create an instance of the graph being used. As such, in playmode, each graph has it’s own instance of blackboard variables as well and thus changing the variable value in one of the instanced prefabs of your character will naturally not change the variable value on all other instances but rather only to that instance. So regarding testing and finding the correct speed value in your example, it can only be done so in one instance at a time in playmode and as soon as the correct value is found and exit playmode, the change the characters prefab speed variable to that desired speed value. The next time you enter playmode and an instance of that prefab is made, all instances will share the same speed variable value initially.
Thanks, yes all agent create an instance of the graph being used, so technically the same as if I had a C# script with defaults (or a bolt 2 class with defaults), changing the instance var would only affect that instance. The slight difference to graph variables is that c# script vars have defaults and overrides on each instance, which I guess matches with how object blackboard vars work? I’m trying to figure out which method would be as similar to a c# script with default vars and instance overrides, using graph vars, object vars or object vars with prefab for setting all of the defaults?
So, using an asset graph seems to be similar to using a c# class/bolt 2 class, and using exposed public graph variables with instance overrides would match c#/bolt 2, except for the fact that the overrides seem to change the graph default as well? Shouldn’t exposed public gameobject instance overrides only ever change the variable on the instance, and never change the graph variable?
As far as I can tell, every instance needs to have it’s own variable override, otherwise the override (any override? the last overridden variable? the last object to have the variable overridden?) will change the graph’s variable default. If the overrides were completely independent and unable to change the graph default, this would be a perfect workaround for a class-type variable system.
Is this a bug? Overrides affect the graph variables: https://gfycat.com/narrowthickhairstreak
So, going forward with a multi-scene game, if I want to add any variables to my gameobject, I’m not sure what to do, since they’d have to be manually added to every object manually in every scene?
Hello again,
Regarding the bug with overrides, yes it is a visual (GUI-only) bug as I’ve explained in your [other post here]
Asset graphs are helpful if you want many completely different type of objects to use the same graph and where you don’t want to use prefabs, but if that is not a requirement, then I think that the simplest approach would be to use Bound Graphs with Prefabs. This way, you will have a single prefab to change when you need to (for example add a new variable) and also each prefab instance can have it’s variables different (overridden) if also need be. I would also probably chose to use GameObject variables instead of Graph Variables, since GameObject variables are the ones that are stored on the Blackboard component found on the GameObject and which is easier to access for all purposes (via other flowscripts, via tasks, or even via code). The Blackboard Component also supports per-variable prefab overrides.
Most of the things above are also supported if you chose to use Graph Assets with exposed public variables instead, except from the fact that they are harder to access from outside the graph (except via code currently).
In both cases and to answer your last questions, if you add a variable to the prefab blackboard (in case of using prefabs) or the Graph Asset local blackboard (in case you use Graph Assets), the newly added variable will appear in all instances and will not have to be added manually in every scene object instance.
Please let me know if that helps 🙂
Thanks!
Join us on Discord: https://discord.gg/97q2Rjh
Hello again, Regarding the bug with overrides, yes it is a visual (GUI-only) bug as I’ve explained in your [other post here] Asset graphs are helpful if you want many completely different type of objects to use the same graph and where you don’t want to use prefabs, but if that is not a requirement, then I think that the simplest approach would be to use Bound Graphs with Prefabs. This way, you will have a single prefab to change when you need to (for example add a new variable) and also each prefab instance can have it’s variables different (overridden) if also need be. I would also probably chose to use GameObject variables instead of Graph Variables, since GameObject variables are the ones that are stored on the Blackboard component found on the GameObject and which is easier to access for all purposes (via other flowscripts, via tasks, or even via code). The Blackboard Component also supports per-variable prefab overrides. Most of the things above are also supported if you chose to use Graph Assets with exposed public variables instead, except from the fact that they are harder to access from outside the graph (except via code currently). In both cases and to answer your last questions, if you add a variable to the prefab blackboard (in case of using prefabs) or the Graph Asset local blackboard (in case you use Graph Assets), the newly added variable will appear in all instances and will not have to be added manually in every scene object instance. Please let me know if that helps Thanks!
Really helpful information, thanks! I think I follow you mostly, just wanted to double-check: I’m using Asset graphs rather than Bound graphs, but since most of the objects using the graphs will be prefabs (as you described) is there any reason why using an Asset graph with a prefab would be different to using a Bound graph with a prefab? I’m using gameobject variables because, as you mentioned, they’reeasier to access for all purposes (via other flowscripts, via tasks, or even via code), but would I be better off using a bound graph instead of an asset graph on a prefab? And are bound graph prefabs using graph variables still restricted to how accessible the variables are to other graphs?
Hello,
Since you are using prefabs, I would recommend using Bound Graphs instead of Asset Graphs since they are easier to work with and also support object references from within the prefab hierarchy. In both cases however (bound/asset), the local graph variables work the same (have the same restrictions as far as accessing the variables in this case).
🙂
Join us on Discord: https://discord.gg/97q2Rjh
Really? I found using asset graphs the gameobject variables could be referenced not only within the prefab, but the instances correctly referenced their own instance objects, I so far haven’t found any downside to using asset graphs?