I'm new to ORK. I want to extend Combatant with some custom fields and behavior, and I'm wondering what's the best way to do this. For example, I want to store a field specifying which move speed type the combatant is currently using. I think I can use the local object variables for this, but then I need to add this variable to every single combatant I'm creating. This isn't great if I decide to add a new field after creating a hundred combatants, as I need to manually add the new variable to each existing combatant.

I'm thus thinking about adding a custom class to store these extra fields, and I'm wondering if this is the right way to go.
  • Well, it depends on the use case, e.g. if your custom fields are used in ORK's systems (e.g. events, formulas or battle AI), using object variables of the combatants is the best way to go. If they're only used in custom functionality outside of ORK, you can stick to custom components on the combatant's prefab.

    You can also blend them together, though. E.g. have a custom component on the prefabs and use it to set some default object variables on the combatant.
    Check out this how-to on getting a game object's combatant. Once you've got the combatant, you can change the combatant's object variables like this:
    combatant.Variables.Set(key, value);
    key is a string, containing the variable key (e.g. moveSpeedType).
    value can be a bool, float, string and Vector3 value you want to use.

    There are also other functions available in the variable handler you access via combatant.Variables. And you don't even have to set up object variables in the combatant, as accessing it like this will automatically create variables on the combatant.
    Please consider rating/reviewing my products on the Asset Store (hopefully positively), as that helps tremendously with getting found.
    If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
  • edited December 2020
    That sounds like a good idea!

    After prodding the code some more, I think I also want to extend CombatantSetting, in addition to Combatant. That is, I also want every single instance of CombatantSetting in the editor to have extra fields, shared for all Combatant instances of that specific CombatantSetting instance. I think I can do this by unchecking local variable in the object variable section, but I'm wondering if it's also possible to automate this. Say if I create a new CombatantSetting in the ORK editor, is it possible to write a script to create the extra variables I need?
    Post edited by Flying_Banana on
  • Adding settings to the combatant will require you to add them to the class and recompiling ORK's gameplay code into the ORKFramework.DLL.

    If you do it via object variables, you can only either use local (i.e. per combatant) or shared object variables via the Object ID.
    Please consider rating/reviewing my products on the Asset Store (hopefully positively), as that helps tremendously with getting found.
    If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
  • Oh! So it's either local variables or shared object variables?

    Is it recommended at all to modify the DLL? Wouldn't it be overwritten when applying an upgrade?
  • Well, that's a general issue with modifications and software updates - you can either lock yourself to a version or have to redo your modification with each update.

    If there's a custom feature you need and can't implement otherwise, go for the modified DLL and only update in case you need a bugfix or a new feature and re-implement your stuff. An alternative is to commission a feature and make it part of ORK's update cycle (i.e. everyone else would also get it).

    As for object variables, yeah - you can either use them in a local mode (or with a unique object ID) or have everyone with the same object ID share the same variables. This isn't limited to combatants, e.g. if you set up an Object Variables component on a regular game object in your scene and use the same object ID as a combatant, it'll also share the same variables.

    You can also use multiple object variable components, e.g. have the combatant's setup use local variables, but adding an object variable component to a child object of the combatant for some shared variables. That way you can access the shared variables via defining the child object (e.g. in Change Game Variables or Check Game Variables nodes).
    Please consider rating/reviewing my products on the Asset Store (hopefully positively), as that helps tremendously with getting found.
    If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
Sign In or Register to comment.