# saving an agent to use it later

**URL:** <https://forums.unrealengine.com/t/saving-an-agent-to-use-it-later/2353550>\
**Category:** Verse\
**Tags:** unreal-editor-for-fortnite, fortnite-creative, question, fortnite\
**Created:** [February 23, 2025, 11:23pm UTC](https://forums.unrealengine.com/t/saving-an-agent-to-use-it-later/2353550 "2025-02-23T23:23:19Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![PlsFocus](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/plsfocus/32/1090249_2.png) [@PlsFocus](https://forums.unrealengine.com/u/PlsFocus)\
**Post date:** [February 23, 2025, 11:23pm UTC](https://forums.unrealengine.com/t/saving-an-agent-to-use-it-later/2353550/1 "2025-02-23T23:23:19Z")

</div>

My issue/question is that `VehicleSpawnedEvent` does not give an Agent, of course. However, I need the agent to be able to set it back into the car. How would I be able to reference the agent?

The script needs to work for 5 players

```verse
using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }

player_car_handler := class(creative_device):

    @editable SuvSpawner : vehicle_spawner_valet_suv_device = vehicle_spawner_valet_suv_device{}

    OnBegin<override>()<suspends>:void=
        SuvSpawner.AgentExitsVehicleEvent.Subscribe(RespawnCar)
        SuvSpawner.VehicleSpawnedEvent.Subscribe(PutPlayerIntoCar)

    RespawnCar(Agent : agent): void =
        SuvSpawner.RespawnVehicle
    
    PutPlayerIntoCar(Agent : agent): void =
        SuvSpawner.AssignDriver(Agent)

```

---

<div class="post-metadata">

**Author:** ![im\_a\_lama](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/im_a_lama/32/995063_2.png) [@im\_a\_lama](https://forums.unrealengine.com/u/im_a_lama)\
**Post date:** [February 24, 2025, 7:54am UTC](https://forums.unrealengine.com/t/saving-an-agent-to-use-it-later/2353550/2 "2025-02-24T07:54:49Z")

</div>

Seems like you need to use `fort_vehicle.GetPassengers()`

---

<div class="post-metadata">

**Author:** ![PlsFocus](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/plsfocus/32/1090249_2.png) [@PlsFocus](https://forums.unrealengine.com/u/PlsFocus)\
**Post date:** [February 24, 2025, 2:04pm UTC](https://forums.unrealengine.com/t/saving-an-agent-to-use-it-later/2353550/3 "2025-02-24T14:04:44Z")

</div>

> [@im\_a\_lama](#):
>
> GetPassengers()

Thanks for the reply, what does it return and do you have the documentation about this function?

---

<div class="post-metadata">

**Author:** ![Mineblo](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/mineblo/32/1203575_2.png) [@Mineblo](https://forums.unrealengine.com/u/Mineblo)\
**Post date:** [February 24, 2025, 2:25pm UTC](https://forums.unrealengine.com/t/saving-an-agent-to-use-it-later/2353550/4 "2025-02-24T14:25:48Z")

</div>

> [@PlsFocus](#):
>
> do you have the documentation about this function?

Here you go:

> **[Verse API reference page for the GetPassengers function | Fortnite...](https://dev.epicgames.com/documentation/en-us/fortnite/verse-api/fortnitedotcom/vehicles/fort_vehicle/getpassengers?)**
>
> Learn technical details about the API for the GetPassengers function in Verse.

Essentially it returns all the fort\_characters in an array.

Here’s an example code that should get the fort characters from a vehicle, goes through the entire list and checks if they have a valid agent associated and if true runs the .Respawn() function on them

```auto
for(FortChar:MyCar.GetPassengers()):
      if(Agent:=FortChar.GetAgent[]):
          Agent.Respawn(vector3{},rotation{})

```

---

<div class="post-metadata">

**Author:** ![PlsFocus](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/plsfocus/32/1090249_2.png) [@PlsFocus](https://forums.unrealengine.com/u/PlsFocus)\
**Post date:** [February 24, 2025, 3:03pm UTC](https://forums.unrealengine.com/t/saving-an-agent-to-use-it-later/2353550/5 "2025-02-24T15:03:36Z")

</div>

I don’t think this will work in this case, everytime the car respawns it should put the player into the car

---

<div class="post-metadata">

**Author:** ![Mineblo](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/mineblo/32/1203575_2.png) [@Mineblo](https://forums.unrealengine.com/u/Mineblo)\
**Post date:** [February 24, 2025, 3:05pm UTC](https://forums.unrealengine.com/t/saving-an-agent-to-use-it-later/2353550/6 "2025-02-24T15:05:10Z")

</div>

Well unfortunately you can’t do that with fort\_vehicle, only the device that spawned it itself has functions to assign players inside cars

---

<div class="post-metadata">

**Author:** ![im\_a\_lama](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/im_a_lama/32/995063_2.png) [@im\_a\_lama](https://forums.unrealengine.com/u/im_a_lama)\
**Post date:** [February 24, 2025, 3:10pm UTC](https://forums.unrealengine.com/t/saving-an-agent-to-use-it-later/2353550/7 "2025-02-24T15:10:39Z")

</div>

`SomeVehicleSpawner.AgentEntersVehicleEvent` will return the agent, then keep this agent and use `SomeVehicleSpawner.AssignDriver(Agent)`

---

<div class="post-metadata">

**Author:** ![PlsFocus](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/plsfocus/32/1090249_2.png) [@PlsFocus](https://forums.unrealengine.com/u/PlsFocus)\
**Post date:** [February 24, 2025, 3:14pm UTC](https://forums.unrealengine.com/t/saving-an-agent-to-use-it-later/2353550/8 "2025-02-24T15:14:54Z")

</div>

To explain further, in my project, I have 5 cars. The player needs to be in the car, always. They select a vehicle by going Into a class selector, and from that point forward the player needs to stay in the car. The car can be destroyed, so every time it respawns, it needs to put the player back into the car he selected.

I think for me the solution would be to assign the player to an ID, that ID is also linked to the vehicle. Then I would always be able to call the Player from anywhere.

---

<div class="post-metadata">

**Author:** ![swaggod](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/swaggod/32/1051181_2.png) [@swaggod](https://forums.unrealengine.com/u/swaggod)\
**Post date:** [February 24, 2025, 7:19pm UTC](https://forums.unrealengine.com/t/saving-an-agent-to-use-it-later/2353550/9 "2025-02-24T19:19:29Z")

</div>

In that case you should use a CustomPlayer class that you store in a map with  
var CustomPlayers : [agent]CustomPlayer = map{}

Have a pool of vehicle spawners so you have enough for each player, and when players are added assign them a vehicle spawner from the pool that you store in your CustomPlayer class, along with any other assets or info you need to know for each character. You can subscribe to AgentEntersVehicleEvent, AgentExitsVehicleEvent, and Destroyed event to run logic on these events.

Learning how to handle custom data per player is a really important part of Verse, here is a tutorial that goes over it very well:  
[https://www.youtube.com/watch?v=TTP4qviK2eM&ab\_channel=MangoVoxel](https://www.youtube.com/watch?v=TTP4qviK2eM&ab_channel=MangoVoxel)

---

<div class="post-metadata">

**Author:** ![PlsFocus](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/plsfocus/32/1090249_2.png) [@PlsFocus](https://forums.unrealengine.com/u/PlsFocus)\
**Post date:** [February 25, 2025, 5:15pm UTC](https://forums.unrealengine.com/t/saving-an-agent-to-use-it-later/2353550/10 "2025-02-25T17:15:14Z")

</div>

Hi, I have made a custom player/game manager script according to the video, but I still don’t know how I can get the player from the map.

What I’d need is a way to call a function that returns the player  
If the players are stored in an array I could Assign every player to the array[0-4], and so calling the function would require an int that returns the player accordingly.

Is this possible? Thanks!

---

<div class="post-metadata">

**Author:** ![swaggod](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/swaggod/32/1051181_2.png) [@swaggod](https://forums.unrealengine.com/u/swaggod)\
**Post date:** [February 25, 2025, 5:51pm UTC](https://forums.unrealengine.com/t/saving-an-agent-to-use-it-later/2353550/11 "2025-02-25T17:51:32Z")

</div>

Not sure what you mean by get the player from the map. If you can share your code and what function you need the player for I can take a look. The vehicle events like AgentEntersVehicle and AgentExitsVehicle return an agent which is interchangeable with player, so you should be able to get what you need from those.

---

<div class="post-metadata">

**Author:** ![PlsFocus](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/plsfocus/32/1090249_2.png) [@PlsFocus](https://forums.unrealengine.com/u/PlsFocus)\
**Post date:** [February 25, 2025, 8:46pm UTC](https://forums.unrealengine.com/t/saving-an-agent-to-use-it-later/2353550/12 "2025-02-25T20:46:53Z")

</div>

What I need, is to be able to put the agent into the car (`SuvSpawner.AssignDriver(Agent)` when the car respawns (`VehicleSpawnedEvent`). But when I call `AssignDriver` there is no agent, so I need to get the agent from somewhere.

What I think could be a solution is to store the agent into an array based on what car it got into, so let’s say you choose car 3 out of 5, it will store you in in `array[2]` (since the index starts at 0)

**Would this be possible or do you have another solution in mind?**

The code I’m referring to:

```verse
using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }

player_car_handler := class(creative_device):

    @editable SuvSpawner : vehicle_spawner_valet_suv_device = vehicle_spawner_valet_suv_device{}

    OnBegin<override>()<suspends>:void=
        SuvSpawner.AgentExitsVehicleEvent.Subscribe(RespawnCar)
        SuvSpawner.VehicleSpawnedEvent.Subscribe(PutPlayerIntoCar) # Puts player into car when spawned

    RespawnCar(Agent : agent): void =
        SuvSpawner.RespawnVehicle
    
    PutPlayerIntoCar(): void =
        SuvSpawner.AssignDriver(Agent) # Gives error since agent is not defined

```

---

<div class="post-metadata">

**Author:** ![swaggod](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/swaggod/32/1051181_2.png) [@swaggod](https://forums.unrealengine.com/u/swaggod)\
**Post date:** [February 25, 2025, 11:08pm UTC](https://forums.unrealengine.com/t/saving-an-agent-to-use-it-later/2353550/13 "2025-02-25T23:08:49Z")

</div>

First off if you want 5 players you’ll need 5 suv spawners as I suggested above, have a pool `@editable SUVPool : []vehicle_spawner_valet_suv_device = array{}`

As I also said above you’ll also need the CustomPlayer data class and an [agent]CustomPlayers map to track which is assigned to what player.  
In my projects I have a Verse device Asset\_Pool that stores all the devices needed in arrays like this, and then you have a function for CheckOut(id : int) and Return(id : int) that tracks the index of your array (if it is checked out) and assigns the asset to the CustomPlayer data. Here is what my customplayer looks like:

CustomPlayer:= class():  
var Assets : PlayerAssets = PlayerAssets{}  
var AssetsID : int = 0  
FC : fort\_character  
var vehicle : ?vehicle\_spawner\_device = false

Once you figure out how to assign data and devices to players through a map you’ll be able to do all the things you’re looking for and more, it is a crucial part of learning Verse.

Also, as the VehicleSpawnedEvent does not pass an agent, you’ll want to call SuvSpawner.Respawn() manually in Verse somewhere you already have the Agent reference.

---

<div class="post-metadata">

**Author:** ![PlsFocus](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/plsfocus/32/1090249_2.png) [@PlsFocus](https://forums.unrealengine.com/u/PlsFocus)\
**Post date:** [February 26, 2025, 12:48pm UTC](https://forums.unrealengine.com/t/saving-an-agent-to-use-it-later/2353550/14 "2025-02-26T12:48:41Z")

</div>

Thank you! This will work for me.

I will handle the respawning of the car myself, if the player dies it will respawn the car and put the player into the car again.

But one more question if you don’t mind 😅, do you know how I can detect if the player has died? The elim manager only sends an event when another agent has killed the player. But in my case the player dies because of a damage barrier or the expotion of the car, so there is no other agent involved.

I tried looking at [this](https://dev.epicgames.com/documentation/en-us/uefn/verse-api/fortnitedotcom/characters/fort_character/eliminatedevent) function, but I don’t really know how I could use it. One thing I need is the agent that has died.

**Thanks again for your last response!**

---

<div class="post-metadata">

**Author:** ![PlsFocus](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/plsfocus/32/1090249_2.png) [@PlsFocus](https://forums.unrealengine.com/u/PlsFocus)\
**Post date:** [February 26, 2025, 1:32pm UTC](https://forums.unrealengine.com/t/saving-an-agent-to-use-it-later/2353550/15 "2025-02-26T13:32:01Z")

</div>

Another thing is that `DestroyVehicle` and `RespawnVehicle` from [class vehicle\_spawner\_device](https://dev.epicgames.com/documentation/en-us/uefn/verse-api/fortnitedotcom/devices/vehicle_spawner_device) do not work for me. Only `AssignDriver` does

**My code (Modified for example):**

```verse
using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }

player_car_handler := class(creative_device):

    @editable SuvSpawner : vehicle_spawner_valet_suv_device = vehicle_spawner_valet_suv_device{} 
    @editable TestTrigger : trigger_device = trigger_device{}

    OnBegin<override>()<suspends>:void=
        SuvSpawner.AgentExitsVehicleEvent.Subscribe(RespawnCar)
        TestTrigger.TriggeredEvent.Subscribe(PutPlayerIntoCar)

    RespawnCar(Agent : agent): void =
        Print("Respawning Vehicle")
        SuvSpawner.DestroyVehicle # This does not work
        SuvSpawner.RespawnVehicle # Also does not work
    
    PutPlayerIntoCar(Agent : ?agent): void =
        Print("Assing Player to car test")
        if (TestAgent := Agent?):
            SuvSpawner.AssignDriver(TestAgent) # Does work

```

---

<div class="post-metadata">

**Author:** ![im\_a\_lama](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/im_a_lama/32/995063_2.png) [@im\_a\_lama](https://forums.unrealengine.com/u/im_a_lama)\
**Post date:** [February 26, 2025, 1:32pm UTC](https://forums.unrealengine.com/t/saving-an-agent-to-use-it-later/2353550/16 "2025-02-26T13:32:28Z")

</div>

because you’re not actually calling them

---

<div class="post-metadata">

**Author:** ![PlsFocus](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/plsfocus/32/1090249_2.png) [@PlsFocus](https://forums.unrealengine.com/u/PlsFocus)\
**Post date:** [February 26, 2025, 1:33pm UTC](https://forums.unrealengine.com/t/saving-an-agent-to-use-it-later/2353550/17 "2025-02-26T13:33:52Z")

</div>

Ah thanks, had to add ()

---

<div class="post-metadata">

**Author:** ![PlsFocus](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/plsfocus/32/1090249_2.png) [@PlsFocus](https://forums.unrealengine.com/u/PlsFocus)\
**Post date:** [February 26, 2025, 1:39pm UTC](https://forums.unrealengine.com/t/saving-an-agent-to-use-it-later/2353550/18 "2025-02-26T13:39:38Z")

</div>

> [@PlsFocus](#):
>
> detect if the player has died

Would you know the answer for this?

---

<div class="post-metadata">

**Author:** ![swaggod](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/swaggod/32/1051181_2.png) [@swaggod](https://forums.unrealengine.com/u/swaggod)\
**Post date:** [February 26, 2025, 5:25pm UTC](https://forums.unrealengine.com/t/saving-an-agent-to-use-it-later/2353550/19 "2025-02-26T17:25:07Z")

</div>

You can take the Agent and do .GetFortCharacter, and with the fort character you can subscribe to EliminatedEvent. This returns an elimResult, then you can get result.EliminatedCharacter to get the character who died. The EliminatingCharacter is an optional so if a barrier killed the player it will return false

---

<div class="post-metadata">

**Author:** ![PlsFocus](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/plsfocus/32/1090249_2.png) [@PlsFocus](https://forums.unrealengine.com/u/PlsFocus)\
**Post date:** [February 26, 2025, 7:36pm UTC](https://forums.unrealengine.com/t/saving-an-agent-to-use-it-later/2353550/20 "2025-02-26T19:36:09Z")

</div>

Thank you bro

[Next page](https://forums.unrealengine.com/t/saving-an-agent-to-use-it-later/2353550.md?page=2)
