I’m building a simple elevator system, and I have two door props that I’m pulling into a Verse script as creative_props, then animating their position using MoveTo.
The weird thing is… this works when I call it from OnBegin on the door itself. But when I later call it from a button activation (through a looping function on another Verse), I get an error that the object has been disposed (even though I’m still looking at it in-game). I have no idea what to try next.
Perhaps there is some other way to access a function like this from another place? Directly calling them from event functions wasn’t possible, so I went this route instead.
The verse script are as follows:
using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/SpatialMath }
elevator_door := class<concrete>(creative_device):
@editable
var DoorLeft<public> : creative_prop = creative_prop{}
@editable
var DoorRight<public> : creative_prop = creative_prop{}
var leftClosedPosition : vector3 = vector3{}
var rightClosedPosition : vector3 = vector3{}
var TransformLeft : transform = transform{}
var TransformRight : transform = transform{}
@editable
var distance<public> : float = 128.0
@editable
var floor<public> : int = 0
var isOpen : logic = false
# Runs when the device is started in a running game
OnBegin<override>()<suspends>:void=
Print("Elevator door start")
set TransformLeft = DoorLeft.GetTransform()
set TransformRight = DoorRight.GetTransform()
set leftClosedPosition = DoorLeft.GetTransform().Translation
set rightClosedPosition = DoorRight.GetTransform().Translation
Print("{ DoorLeft.GetTransform().Translation}")
Print("{ DoorRight.GetTransform().Translation}")
block:
Open()
Sleep(1.0)
Close()
Open<public>()<suspends>:void=
Print("Door opening")
TargetLeft : vector3 = vector3 {X:= leftClosedPosition.X, Y:= leftClosedPosition.Y - 128.0, Z:= leftClosedPosition.Z}
TargetRight : vector3 = vector3 {X:= leftClosedPosition.X, Y:= rightClosedPosition.Y + 128.0, Z:= leftClosedPosition.Z}
lRot := DoorLeft.GetTransform().Rotation
rRot := DoorRight.GetTransform().Rotation
block:
Result := sync:
DoorLeft.MoveTo(TargetLeft, lRot, 1.0)
DoorRight.MoveTo(TargetRight, rRot, 1.0)
set isOpen = true
Close<public>()<suspends>:void=
Print("Door closing")
TargetLeft : vector3 = leftClosedPosition
TargetRight : vector3 = rightClosedPosition
Print("Moving")
block:
Result := sync:
DoorLeft.MoveTo(TargetLeft, TransformLeft.Rotation, 1.0)
DoorRight.MoveTo(TargetRight, TransformRight.Rotation, 1.0)
set isOpen = false
And the elevator button (name needs a refactor)
using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /Verse.org/Verse }
using { /UnrealEngine.com/Temporary/SpatialMath }
elevator_button := class<concrete>(creative_device):
@editable
MyButton<public> : button_device = button_device{}
@editable
MyOuterButton<public> : button_device = button_device{}
@editable
var baseFloor<public> : int = 0
var basePosition : vector3 = vector3{}
var currentFloor : int = 0
var targetFloor : int = 0
var activated : logic = false
var called : logic = false
@editable
MyCabin<public> : creative_prop = creative_prop{}
@editable
MyDoors<public> : []elevator_door = array{elevator_door{}}
# Runs when the device is started in a running game
OnBegin<override>()<suspends>:void=
Print("Elevator start")
MyButton.InteractedWithEvent.Subscribe(OnActivated)
MyOuterButton.InteractedWithEvent.Subscribe(OnOuterActivated)
set basePosition = MyCabin.GetTransform().Translation
MovementFunction()
OnActivated(Agent : agent ) : void=
Print("USED BUTTON")
# Check state (not moving or called down)
if ( activated = false):
# move to next floor
set targetFloor = currentFloor+1
set activated = true
OnOuterActivated(Agent : agent ) : void=
Print("USED BOTTOM BUTTON")
set called = true
MovementFunction()<suspends> : void=
loop:
if (called = true):
if ( currentFloor = baseFloor ):
block:
OpenDoors()
else:
set targetFloor = baseFloor
block:
CloseDoors()
MoveTo()
OpenDoors()
set called = false
else:
if (activated = true):
block:
CloseDoors()
MoveTo()
OpenDoors()
set activated = false
Sleep(0.1)
MoveTo()<suspends> : void=
Print("Moving to floor {targetFloor}")
Transform := MyCabin.GetTransform()
Target : vector3 = basePosition + vector3 {X:= 0.0, Y:= 0.0, Z:= 256.0 * 4 * (targetFloor - baseFloor)}
Print("Moving")
MyCabin.MoveTo(Target, Transform.Rotation, 5.0)
Print("Done Moving")
set currentFloor = targetFloor
CloseDoors()<suspends> : void=
Print("Closing Doors")
# close doors at current floor
if ( Door := MyDoors[currentFloor]):
if ( Door.isOpen = true ):
Door.Close()
OpenDoors()<suspends> : void=
Print("Opening Doors")
#open doors at current floor
if ( Door := MyDoors[currentFloor]):
if ( Door.isOpen = false ):
Door.Open()