I have a RPG system, where the event are resources, called by a Node.
I’m writing a functionality, where upon triggering, the Node that holds the event resource will be teleported to a specific spot in the node tree. (It will require reparent() so simply export Vector2 wouldn’t work.)
Now, I can make a new Node class for it, and just let it receive a signal from the event resource, but for the spirit of the consistency, I want the logic to be within the Event Resource.
However, in order to reparent it, I’ll have to set the node to reparent to in the editor, which is what I haven’t figure out.
Use a node to run get_node I believe your player will work. The path will be evaluated relative to the player though, so it may help to try passing in a parent of map or world parameter and use that.
func trigger(_triggered_with: EventTriggeror, _triggered_by: Player):
var destination: Marker2D = _triggered_by.get_node(move_to)
extends Event
class_name MoveTriggeror
@export_node_path("Marker2D") var move_to: NodePath
func trigger(_triggered_with: EventTriggeror, _triggered_by: Player):
var destination: Marker2D = _triggered_with.get_node_or_null(move_to)
if destination != null:
_triggered_with.position = Vector2.ZERO
_triggered_with.reparent(destination, false)
This is what I settled with. Since the path is broke once the reparent is done, I added a null check just to avoid the red warning.
This would break if I want the node to move multiple time, but it’s good enough for the project, thanks for helping.