I just found myself needing to call an event from C# so thought I'd post the process here for any other noobs.

Add the using ORKFramework; to the top of your script.

Create a global object to call the events from ORKFramework.Events.GameEvent gameEvent = new ORKFramework.Events.GameEvent();

Create an inspector field to drag and drop the event you've created with ork into public ORKEventAsset eventAsset;

Now when you need to call the event simply use gameEvent.CallEvent(eventAsset, 0);
  • That's not really the correct way to do it, and most likely wont work for events that contain any kind of time related stuff (e.g. Wait steps).

    You'll either first need to set up an Event Interaction component and call it's StartEvent function, or use the following code to start an event:

    ORK.Core.GameObject.AddComponent<GameEventTicker>().StartEvent(ORKGameEvent eventAsset, IEventStarter starter, GameObject startingObject, bool inPause);
    The starter is an interface to receive notification when an event finished - you can use null if you don't need it.
    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 2019
    @gamingislove

    The code you gave above works fine for object that has only one event attached to it.

    1.
    However, just in case we have several events in an object and want to call the second event, third event, and so on in the same object.
    How can we use the code?

    2.
    Another question, if we want to call an event in a specific name of child object.
    How to use the code?

    Thanks in advance.
    Post edited by bomobee on
  • 1) Well, the code didn't actually use any event set up on a game object, just started an event with an event asset and game objects you pass on.
    If you have multiple event interactions added to a game object, I'd try getting them all:
    EventInteraction[] interaction = gameObject.GetComponents<EventInteraction>();
    Theoretically they should be returned in the order they're attached, but I don't think Unity 100% guarentees that ...

    2) You'll have to get the child object from the game object - ORK has a helpe class for that:
    gameObject = TransformHelper.GetChildObject("path/to/child", gameObject);
    It'll return either the found child object or the game object itself if no child was found for the path.
    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 2019
    @gamingislove

    Thanks a lot for your help.
    I will try them out and see the result.

    I believe I figured out a way to solve my issue from the answer you gave above.

    Thanks so much.
    Post edited by bomobee on
Sign In or Register to comment.