# How to hold an agent variable in class variable?

**URL:** <https://forums.unrealengine.com/t/how-to-hold-an-agent-variable-in-class-variable/860438>\
**Category:** Verse\
**Tags:** unreal-editor-for-fortnite, fortnite-creative, question, fortnite\
**Created:** [April 6, 2023, 9:54am UTC](https://forums.unrealengine.com/t/how-to-hold-an-agent-variable-in-class-variable/860438 "2023-04-06T09:54:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![cherlix](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@cherlix](https://forums.unrealengine.com/u/cherlix)\
**Post date:** [April 6, 2023, 9:54am UTC](https://forums.unrealengine.com/t/how-to-hold-an-agent-variable-in-class-variable/860438/1 "2023-04-06T09:54:00Z")

</div>

Hi folks,

I explain what I want to achieve at first. I have a volume in the level. When the player enters into it, it will start a timer. When the timer is completed, I would like to let the player win the game.

Firstly, I define a class to hold the volume and timer

```auto
gameflow_management_device := class(creative_device):
    @editable
    EvacuationTimer : timer_device = timer_device{}

    @editable
    EvacuationZone : mutator_zone_device = mutator_zone_device{}

```

And this class subscribes volume’s AgentEntersEvent. When the event is triggered, I tried to hold the agent for the future use. But It seems that I can not hold it in gameflow\_management\_device class because there is no pointer or reference of C++ in verse, and agent is epic internal class, so I can not declare an agent variable in class either.

Then I tried alternative way. I use agent to start the timer. When timer’s complete event is triggered, so I can get the agent from handler’s argument:

```auto
HandleEvacuationTimerComplete(Agent:?agent):void=

```

But I do not know how to convert ?agent to an agent with failable context.

I am not sure if I implement the idea in the right way. Any idea?

Cheers

---

<div class="post-metadata">

**Author:** ![CosmicDanAU](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/cosmicdanau/32/642728_2.png) [@CosmicDanAU](https://forums.unrealengine.com/u/CosmicDanAU)\
**Post date:** [April 6, 2023, 1:25pm UTC](https://forums.unrealengine.com/t/how-to-hold-an-agent-variable-in-class-variable/860438/2 "2023-04-06T13:25:52Z")

</div>

Instead of using Agent, maybe convert to/from the `fort_character` type and store that, this definitely works. You can use `Agent.GetFortCharacter[]` and `FortCharacter.GetAgent[]`.

---

<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 6, 2023, 7:45pm UTC](https://forums.unrealengine.com/t/how-to-hold-an-agent-variable-in-class-variable/860438/3 "2023-04-06T19:45:44Z")

</div>

Hi @cherlix,

The `?agent` type represents an “optional agent”. In regular verse code variables must have a value. For example, if the type is `agent` you can assume that value is always a valid agent. The optional type means that this could be an `agent` or it could be `false`. To check this you can write this:

```auto
# Check if Agent is valid. If it is, assign it to ValidAgent.
if (ValidAgent:agent = Agent?):
    DoThingWithAgent(ValidAgent)

# Shorter version of the same code. ValidAgent being type :agent is 
# automatically done by the Verse compiler
if (ValidAgent := Agent?):
    DoThingWithAgent(ValidAgent)

```

> **[Option](https://dev.epicgames.com/documentation/en-us/uefn/option-in-verse)**
>
> The option type can contain one value or can be empty.

---

<div class="post-metadata">

**Author:** ![cherlix](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@cherlix](https://forums.unrealengine.com/u/cherlix)\
**Post date:** [April 7, 2023, 3:05am UTC](https://forums.unrealengine.com/t/how-to-hold-an-agent-variable-in-class-variable/860438/4 "2023-04-07T03:05:22Z")

</div>

Thanks for the information. I will try it out.

---

<div class="post-metadata">

**Author:** ![el\_gato\_mutante](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@el\_gato\_mutante](https://forums.unrealengine.com/u/el_gato_mutante)\
**Post date:** [April 6, 2024, 9:05pm UTC](https://forums.unrealengine.com/t/how-to-hold-an-agent-variable-in-class-variable/860438/5 "2024-04-06T21:05:48Z")

</div>

“The left hand side of this definition is an expression that cannot be defined” i got that error
