Search Unity

Behaviour Designer - How to setup UnityEvents with the "debug" inspector?

Discussion in 'Scripting' started by nicmarxp, May 10, 2019.

  1. nicmarxp

    nicmarxp

    Joined:
    Dec 3, 2017
    Posts:
    406
    I'm using Opsive behaviour designer (which is amazing), and I'm trying to add an event, to start a particle system, when a custom patrolling task reaches a waypoint.

    To generalize the task, I added a UnityEvent so I can assign a GameObject, and run a method from any component. The code for my task has these lines:
    Code (CSharp):
    1. public UnityEvent waypointReachedEvent;
    2. public UnityEvent waypointLeavingEvent;
    As you can see in my first image below, it shows up in a user unfriendly way, like it shows in Debug mode, and I think Behaviour Designer doesn't use the correct inspector, and doesn't allow Odin or anything like that.

    However, I tried to fill in the fields to call the Event, like this:
    Target: Sparks (dragged)
    Method: ParticleEvents.StartParticles (Manually typed, but this is what it looks like when selecting in the dropdown in the usual inspector, see image below)

    In my task code, I call it like:
    Code (CSharp):
    1. waypointReachedEvent?.Invoke();
    But it doesn't get called.

    Also there seems to be a bug when I change waypointReachedEvent calls Size, it also changes the waypointLeavingEvent calls size, and at one moment, I changed the method to call on one of them, and it changed in the other one. Not sure if this is a Unity issue or with Behaviour Designer.

    If anyone have any ideas how to trigger events from Behaviour Designers tasks and not having to hard code them, I'd be very happy to know!

    Here's the "debug" look, which shows up in Behaviour Designers inspector.


    Here's what it normally looks like:
     
  2. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,296
    You'd need a custom property drawer to draw it inside task inspector.
    https://opsive.com/support/documentation/behavior-designer/object-drawers/

    Also, instead of using UnityEvents, you could use Behavior Designer events instead.
    So when those are called, simply call your events (?.Invoke()) attached to some custom MonoBehaviour.

    Something like this:
    TaskEvent -> Catched by MonoBehaviour -> Invoke -> UnityEvent