Trying to use listenable
s to create device interactions that are not 1:1 (1 device directly bound to another device) is extremely painful right now.
For instance, let’s say you want to monitor the 40 vehicle spawners in your level to respawn a vehicle whenever a player exits a vehicle.
AgentExitsVehicleEvent
tells you when an agent exits the vehicle, but it doesn’t give you the vehicle_spawner_device
that called the event. So now you have to write your own little tracking system to map vehicle spawners to players😩
This is the same situation for literally every device in the game e.g.:
- Vending machines/ItemSpawnedEvent
- trigger_device/TriggeredEvent
- trick_tile_device/ActivatedEvent
- tracker_device/CompleteEvent
- timer_device/SuccessEvent
This was the same situation back when UE4’s Hit/Overlap events didn’t return the primitive component and actor that was firing the event. Luckily this was remedied. We need a similar standard for fortnite listenables, where perhaps the first argument is always this
1 Like
I agree more info passed would be extremally helpful. But for now, you can create a callback handler class that passes the additional references you need to what device triggered the event. Something like this: (untested!)
# custom callback handler that passes the device that triggered the event
CustomCallbackHandler := class():
Manager : test_callback_device
Device : vehicle_spawner_device
HandlerFunction(Agent:agent):void=
Manager.OnEventTriggered(Agent, Device)
test_callback_device := class(creative_device):
@editable
Devices : []vehicle_spawner_device = array{}
OnBegin<override>()<suspends>:void=
for(X -> Device : Devices):
# pass reference to callback
Device.AgentExitsVehicleEvent.Subscribe(CustomCallbackHandler{Manager:=Self, Device:=Device}.HandlerFunction)
OnEventTriggered(Agent:agent, Device:vehicle_spawner_device):void=
# do something....
3 Likes
wooooooowww, thank you for this!
I had no idea you could construct a class, initialize its members and return a pointer to the instantiated class function all in one blow. This expanded my mind and made my implementation trivial.
What is the advantage of this syntax? The X seems unused. Force of habit for more complex loops?
1 Like
The X gives you the index in the loop, but yes unused in this example, just out of habit.
1 Like