How to store a fort_vehicle in a variable

Hi All,
I’m fairly new to Verse and UEFN, and I’m trying to store a fort_vehicle when it spawns, and then get the location of that vehicle later, when I need it (say to teleport an object near it).

I cannot figure out how to store it. I see this feature request, which is exactly what I want - No way to obtain `fort_vehicle` from a `vehicle_spawner_device` at a later point of time and they allude to the fact that it’s currently possible, but kludgy. I’ll take kludgy.

I don’t want anything to do with a player that might or might not have ever driven the vehicle to its new location, and may no longer be in the game, I’m looking for the vehicle itself. I have seen some other posts that get it from the playercharacter, and they get close, but not quite a solution.

The closest I can get is to initialize the variable wrapped with an optional… but then I cannot get the GetTransform from the optional ?fort_vehicle like I can from a known fort_vehicle! How can I get the location? Or is there a better way of approaching this? Thanks in advance!

using { /UnrealEngine.com/Temporary/SpatialMath }
using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }
using { /Fortnite.com/Vehicles }

simple_vehicle_location := class(creative_device):

    @editable MyButton : button_device = button_device{}
    @editable BusSpawner : vehicle_spawner_armored_battle_bus_device = vehicle_spawner_armored_battle_bus_device{}
    
    #create a reference to the bus, which is false for now. so it uses the ?fort_vehicle syntax to be false.
    var BusReference : ?fort_vehicle = false
    var BusPosition : vector3 = vector3{X:=0.0,Y:=0.0,Z:=0.0}


    # Runs when the device is started in a running game
    OnBegin<override>()<suspends>:void=
        BusSpawner.SpawnedEvent.Subscribe(OnStoreBus)
        MyButton.InteractedWithEvent.Subscribe(OnButtonPressed)
   
    OnStoreBus(RealBus : fort_vehicle):void =
        # here, when setting the ?fort_vehicle, we need to use the option
        set BusReference = option{RealBus}
        set BusPosition = RealBus.GetTransform().Translation # this works!
        Print("bus location: {RealBus.GetTransform().Translation}") #this works!

    OnButtonPressed (Agent: agent):void = 
        Print("new bus location: {BusReference.GetTransform().Translation}") # this does NOT work. Error at GetTransform "Unknown member `GetTransform` in `?fort_vehicle`.(3506)"
        if(MyVehicle:fort_vehicle = BusReference): # my failed attempts at trying to cast "BusReference" as a fort_vehicle
            if(Vehicle:= fort_vehicle[MyVehicle]):
                set BusPosition = Vehicle.GetTransform().Translation

I figured it out! I just needed to see an example of how to get an optional value, which I found in this example here.

Er, it was also clearly outlined in the Option documentation.

Whatever, here’s a summary for anyone else who is new to this. Basically, to initialize a variable:

var BusReference : ?fort_vehicle = false

Then to set it:

set BusReference = option{RealBus}

Then to get from it:

if(MyVehicle:= BusReference?):
            Print("bus location: {MyVehicle.GetTransform().Translation}")

Full code below:

using { /UnrealEngine.com/Temporary/SpatialMath }
using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }
using { /Fortnite.com/Vehicles }

simple_vehicle_location := class(creative_device):

    @editable MyButton : button_device = button_device{}
    @editable BusSpawner : vehicle_spawner_armored_battle_bus_device = vehicle_spawner_armored_battle_bus_device{}
    
    #create a reference to the bus, which is false for now. so it uses the ?fort_vehicle syntax to be false.
    var BusReference : ?fort_vehicle = false
    var BusPosition : vector3 = vector3{X:=0.0,Y:=0.0,Z:=0.0}


    # Runs when the device is started in a running game
    OnBegin<override>()<suspends>:void=
        BusSpawner.SpawnedEvent.Subscribe(OnStoreBus)
        MyButton.InteractedWithEvent.Subscribe(OnButtonPressed)
   
    OnStoreBus(RealBus : fort_vehicle):void =
        # here, when setting the ?fort_vehicle, we need to use option
        set BusReference = option{RealBus}
        set BusPosition = RealBus.GetTransform().Translation # this works!
        Print("bus location: {RealBus.GetTransform().Translation}") #this works!

    OnButtonPressed (Agent: agent):void = 
        if(MyVehicle:= BusReference?): # THIS is the format!
            Print("bus location: {MyVehicle.GetTransform().Translation}") # this works!!!