# How do i convert from type ?agent to agent... im so confused with optionals

**URL:** <https://forums.unrealengine.com/t/how-do-i-convert-from-type-agent-to-agent-im-so-confused-with-optionals/1258390>\
**Category:** Verse\
**Tags:** unreal-editor-for-fortnite, fortnite-creative, fortnite\
**Created:** [August 12, 2023, 2:23am UTC](https://forums.unrealengine.com/t/how-do-i-convert-from-type-agent-to-agent-im-so-confused-with-optionals/1258390 "2023-08-12T02:23:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mneko24](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@mneko24](https://forums.unrealengine.com/u/mneko24)\
**Post date:** [August 12, 2023, 2:23am UTC](https://forums.unrealengine.com/t/how-do-i-convert-from-type-agent-to-agent-im-so-confused-with-optionals/1258390/1 "2023-08-12T02:23:27Z")

</div>

☹ why cant this just be cpp

---

<div class="post-metadata">

**Author:** ![Ben85](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Ben85](https://forums.unrealengine.com/u/Ben85)\
**Post date:** [August 12, 2023, 7:07am UTC](https://forums.unrealengine.com/t/how-do-i-convert-from-type-agent-to-agent-im-so-confused-with-optionals/1258390/2 "2023-08-12T07:07:02Z")

</div>

Try the following (where `Agent` is of type `?agent`):

```auto
if (CastAgent := agent[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 12, 2023, 8:23pm UTC](https://forums.unrealengine.com/t/how-do-i-convert-from-type-agent-to-agent-im-so-confused-with-optionals/1258390/3 "2023-08-12T20:23:44Z")

</div>

Like this:

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

```

---

<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 13, 2023, 11:43am UTC](https://forums.unrealengine.com/t/how-do-i-convert-from-type-agent-to-agent-im-so-confused-with-optionals/1258390/4 "2023-08-13T11:43:57Z")

</div>

Here are some additional examples of how to use the optionals:

```auto
OptionalsExample():void=

    # Value is maybe defined
    var MaybeValue: ?int = false

    # Check there is a value and use it
    if. Value := MaybeValue?
    then. Print("Value is defined as {Value}")

    # Check the value is not defined
    if. not MaybeValue?
    then. Print("There is no value defined")
    
    # Value is definitely defined
    DefoValue: int = 0

    # Use `option{}` to assign it to an optional of same type
    set MaybeValue = option{DefoValue}

    if. Value := MaybeValue? then. Print("{Value}") # Prints "0"

```
