Skip to content

Latest commit

 

History

History
38 lines (20 loc) · 2.05 KB

events.md

File metadata and controls

38 lines (20 loc) · 2.05 KB

Events in Visual Scripts

Visual Scripting supports binding for various events for easier gameplay scripting. Follow this documentation page to learn how to use them in your project.

How to handle trigger event?

Onve you've created Visual Script use Bind XXX node to register custom function for event that will be executed every time event gets called. Flax supports registering member or static functions to member and static events.

Firstly, override OnEnable method.

Override OnEnable method in Visual Script

Then use Get Actor node from Script class and Cast node to cast it to PhysicsColliderActor.

Cast Actor to Physicsc Collider Actor

Now, add Bind TriggerEnter method and connect it to Cast outputs. We will use it to register for trigger collider to call our function every time something enters the trigger.

Bind Trigger Enter Event

As you can see it shows the handler function dropdown menu as disabled which means there are no valid functions on a graph to call for event. Let's use red button to quickly create new event handler function and use it in that bind node.

Add Trigger Event Handler Function

After that you can use this function to perform any custom logic every time this collider gets triggered. In this example we simply print the custom message with the object name that activated the trigger

Event Handler Function

Finally we can test this script. Create collider (eg. box collider), adjust it's size and check Is Trigger, then add the script we've created to it.

Trigger Event Setup

Then you can play game and see the log print when something enters this trigger.

Trigger Event Showcase

Tip

You can manually unregister function from event by using Unbind XXX node. Also, Flax will unregister event automatically when script gets deleted.