I have the battle end event for escaping setup. What's the best way to call the event from a custom button instead of going through the Battle Menu?
  • Depends on where your custom button is defined.

    If it's part of a HUD in ORK, you can use a click action on the HUD element, calling a global event with a Use Battle Action node for this.

    If it's in a custom UI, you can do it by code like this:
    combatant.Actions.Add(new EscapeAction(combatant), newTurn);
    combatant is the Combatant instance who'll use the action, newTurn is either true or false depending on if this should start/initiate a new turn (the action will not be added if that fails, e.g. the combatant already is in a new turn - so you'll usually use false here).
    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!
  • I tried using the code you provided, but I'm getting NullReferenceException: Object not set to an instance of an object. This is the code I used to access the combatant:
    combatantComponent = GetComponent<CombatantComponent>();
    combatant = combatantComponent.combatant;
    combatant.Actions.Add(new EscapeAction(combatant), false);

    Specifically, Unity is giving me error on the second line, where I set the combatant variable.
  • That means the CombatantComponent wasn't found on the game object. Is it added (in-game) on the same game object as this code's component is attached to?

    The CombatantComponent is added by ORK automatically when spawning a combatant, usually at the root of the game object. If your custom component isn't attached to the the combatant's root, you'll need to either search it within the hierarchy (e.g. GetComponentInParent or GetComponentInChildren) or directly use the game object of the combatant.

    Or, if you just want to add that to the player - you can access the player combatant via:
    ORK.Game.ActiveGroup.Leader
    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!
  • I used ORK.Game.ActiveGroup.Leader and it works now, thanks.
Sign In or Register to comment.