Skip to content

Instantly share code, notes, and snippets.

@griffi-gh
Last active November 16, 2025 15:31
Show Gist options
  • Select an option

  • Save griffi-gh/24797025cc41a8d3f06efb849aac5b95 to your computer and use it in GitHub Desktop.

Select an option

Save griffi-gh/24797025cc41a8d3f06efb849aac5b95 to your computer and use it in GitHub Desktop.
Non-experimental pure-verse reimplementation of Verse `scene_event` for Fortnite/UEFN
using. /Verse.org/SceneGraph
# An event which can be sent through the scene graph.
_scene_event<public> := interface() {}
_on_receive<public> := interface() {
# Respond to an event being propagated through the scene graph.
# Returns if the event is consumed, in which case the event will not be passed to the next entity, depending on how the event is being sent through the hierarchy.
_OnReceive<public>(Event: _scene_event): logic = false;
}
# Respond to an event being propagated through the scene graph.
# Returns if the event is consumed, in which case the event will not be passed to the next entity, depending on how the event is being sent through the hierarchy.
(InComponent: component).OnReceive<public>(Event: _scene_event): logic = {
if (Interface := _on_receive[InComponent]):
return Interface._OnReceive(Event);
false
}
# Send a scene event to only this entity.
# Returns true if the event was consumed.
(InEntity: entity).SendDirect<public>(Event: _scene_event): logic = {
var Consumed: logic = false;
for (Component: InEntity.GetComponents()):
Result := Component.OnReceive(Event);
if (Result?). set Consumed = true;
Consumed
}
# Send a scene event to this entity and all of its descendants.
# OnReceive will be invoked for each entity.
# Consuming the event at any entity will halt propagation down that subtree.
# Entities are traversed in breadth-first order, i.e. each layer is evaluated before moving deeper.
# Returns true if the event was consumed.
(InEntity: entity).SendDown<public>(Event: _scene_event): logic = {
var Consumed: logic = false;
var CurrentLevel: []entity = array{InEntity};
loop:
if (CurrentLevel.Length = 0). break;
var NextLevel: []entity = array{};
for (Entity: CurrentLevel):
Result := Entity.SendDirect(Event);
if (Result?):
set Consumed = true;
else:
set NextLevel += for (Child: Entity.GetEntities()). Child;
set CurrentLevel = NextLevel;
Consumed
}
# Send a scene event to this entity and its ancestors.
# Events do not propagate beyond the Simulation Entity.
# OnReceive will be invoked for each entity.
# Consuming the event will halt propagation to the next ancestor.
# Returns true if the event was consumed.
(InEntity: entity).SendUp<public>(Event: _scene_event): logic = {
var CurEntity: entity = InEntity;
loop:
Result := CurEntity.SendDirect(Event);
if (Result?). return true;
if (Parent := CurEntity.GetParent[]) {
set CurEntity = Parent;
} else {
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment