# Agent to Player

**URL:** <https://forums.unrealengine.com/t/agent-to-player/883843>\
**Category:** Programming & Scripting\
**Tags:** unreal-editor-for-fortnite, fortnite-creative, fortnite\
**Created:** [April 10, 2023, 5:20pm UTC](https://forums.unrealengine.com/t/agent-to-player/883843 "2023-04-10T17:20:46Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![LuckofBuck](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/luckofbuck/32/677363_2.png) [@LuckofBuck](https://forums.unrealengine.com/u/LuckofBuck)\
**Post date:** [April 10, 2023, 5:20pm UTC](https://forums.unrealengine.com/t/agent-to-player/883843/1 "2023-04-10T17:20:46Z")

</div>

How do you convert an “agent” type to a “player”? The vehicle event forces an agent and I just want to respawn the player.

```auto
    OnAgentExitsVehicle(Agent : agent): void= 
        Print("OnAgentExitsVehicle")

        #agent to player here then will .Respawn() the player
        

```

---

<div class="post-metadata">

**Author:** ![Incredulous\_Hulk](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/incredulous_hulk/32/924210_2.png) [@Incredulous\_Hulk](https://forums.unrealengine.com/u/Incredulous_Hulk)\
**Post date:** [April 10, 2023, 5:39pm UTC](https://forums.unrealengine.com/t/agent-to-player/883843/2 "2023-04-10T17:39:50Z")

</div>

`player` inherits from `agent`. So you should be able to attempt to cast to `player` to see if the provided `agent` is in fact a `player` instance.

Example:

```auto
if (Player := player[Agent]):
    # Do something with Player here now that we know this is in fact a Player type

```

---

<div class="post-metadata">

**Author:** ![LuckofBuck](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/luckofbuck/32/677363_2.png) [@LuckofBuck](https://forums.unrealengine.com/u/LuckofBuck)\
**Post date:** [April 10, 2023, 5:57pm UTC](https://forums.unrealengine.com/t/agent-to-player/883843/3 "2023-04-10T17:57:30Z")

</div>

Thank you!

---

<div class="post-metadata">

**Author:** ![itascreations](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@itascreations](https://forums.unrealengine.com/u/itascreations)\
**Post date:** [July 14, 2023, 1:09pm UTC](https://forums.unrealengine.com/t/agent-to-player/883843/5 "2023-07-14T13:09:59Z")

</div>

You can’t convert it, but you can assing it to a ?agent var. For example:

```auto
var MaybeAgent : ?agent = false #We declare the ?agent var without passing anything
if (Player := player[Agent]){
    # Do something with Player here now that we know this is in fact a Player type
    set MaybeAgent = option{Agent}}

```

---

<div class="post-metadata">

**Author:** ![PoshyPoshLad1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@PoshyPoshLad1](https://forums.unrealengine.com/u/PoshyPoshLad1)\
**Post date:** [August 5, 2023, 4:20am UTC](https://forums.unrealengine.com/t/agent-to-player/883843/6 "2023-08-05T04:20:03Z")

</div>

Having a similar issue, I want to check if the agent who eliminated this creature and if its a player, add a point. What should I do here?

![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/0/1/6/0161c0c707cc0add84be060ec73b5beb8fb349d4.png)

---

<div class="post-metadata">

**Author:** ![ManualPotato](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/manualpotato/32/1144902_2.png) [@ManualPotato](https://forums.unrealengine.com/u/ManualPotato)\
**Post date:** [August 5, 2023, 8:45am UTC](https://forums.unrealengine.com/t/agent-to-player/883843/7 "2023-08-05T08:45:12Z")

</div>

Read the error. It should be telling you you have ambiguous definition of `Agent`. Name your local `Agent` variable something different to the `Agent` input parameter. You also need to check your `Agent` of type `?agent` actually exists before trying to use it.

---

<div class="post-metadata">

**Author:** ![PoshyPoshLad1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@PoshyPoshLad1](https://forums.unrealengine.com/u/PoshyPoshLad1)\
**Post date:** [August 13, 2023, 3:11am UTC](https://forums.unrealengine.com/t/agent-to-player/883843/9 "2023-08-13T03:11:42Z")

</div>

How would I check my Agent of type ?agent?

---

<div class="post-metadata">

**Author:** ![Twin01](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/twin01/32/1077777_2.png) [@Twin01](https://forums.unrealengine.com/u/Twin01)\
**Post date:** [August 13, 2023, 5:23am UTC](https://forums.unrealengine.com/t/agent-to-player/883843/10 "2023-08-13T05:23:01Z")

</div>

```auto
    Foo(MaybeAgent: ?agent): void =
        if (Agent := MaybeAgent?):
            # Do stuff with 'Agent'

```

---

<div class="post-metadata">

**Author:** ![PoshyPoshLad1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@PoshyPoshLad1](https://forums.unrealengine.com/u/PoshyPoshLad1)\
**Post date:** [August 15, 2023, 2:40am UTC](https://forums.unrealengine.com/t/agent-to-player/883843/11 "2023-08-15T02:40:47Z")

</div>

Thanks! I got the following to work with my code:

`if(Player := player[Agent?].GetFortCharacter[]):`

---

<div class="post-metadata">

**Author:** ![ManualPotato](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/manualpotato/32/1144902_2.png) [@ManualPotato](https://forums.unrealengine.com/u/ManualPotato)\
**Post date:** [August 15, 2023, 10:57am UTC](https://forums.unrealengine.com/t/agent-to-player/883843/12 "2023-08-15T10:57:42Z")

</div>

> [@PoshyPoshLad1](#):
>
> if(Player := player[Agent?].GetFortCharacter):

You can make that:

```auto
if(FortCharacter := Agent?.GetFortCharacter[]):

```

Because `GetFortCharacter` is available on `agent`, so there is no need to cast to `player`. The variable name makes it clear it’s a reference to a `fort_character` and not a `player`.

---

<div class="post-metadata">

**Author:** ![PoshyPoshLad1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@PoshyPoshLad1](https://forums.unrealengine.com/u/PoshyPoshLad1)\
**Post date:** [August 15, 2023, 2:41pm UTC](https://forums.unrealengine.com/t/agent-to-player/883843/13 "2023-08-15T14:41:37Z")

</div>

> [@ManualPotato](#):
>
> `if(FortCharacter := Agent?.GetFortCharacter[]):`

Gotcha thx!

---

<div class="post-metadata">

**Author:** ![Rodriges2.7](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Rodriges2.7](https://forums.unrealengine.com/u/Rodriges2.7)\
**Post date:** [February 2, 2024, 12:36pm UTC](https://forums.unrealengine.com/t/agent-to-player/883843/14 "2024-02-02T12:36:56Z")

</div>

Hey i am super lost right now and saw that you understand Agents and verse so i thought i would ask you. I am triing to get the tracker Value only for the the Player playing right now but it switches betwen all players (i only tried it with two) showing my tracked value and the my enemies would be super happy over some help 🙂

this is my code:  
OnBegin():void =

```auto
    loop: 
        for. Player : (GetPlayspace().GetPlayers())
        do:
            TargetValue := Tracker.GetValue(Player)
            Print("Tracker is at {TargetValue}")

```
