# Why comparing optional with non-optional compiles well and always fails?

**URL:** <https://forums.unrealengine.com/t/why-comparing-optional-with-non-optional-compiles-well-and-always-fails/2534074>\
**Category:** Verse\
**Tags:** unreal-editor-for-fortnite, fortnite-creative, question, fortnite\
**Created:** [May 30, 2025, 1:12pm UTC](https://forums.unrealengine.com/t/why-comparing-optional-with-non-optional-compiles-well-and-always-fails/2534074 "2025-05-30T13:12:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Konerds](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Konerds](https://forums.unrealengine.com/u/Konerds)\
**Post date:** [May 30, 2025, 1:12pm UTC](https://forums.unrealengine.com/t/why-comparing-optional-with-non-optional-compiles-well-and-always-fails/2534074/1 "2025-05-30T13:12:05Z")

</div>

```verse
X :?int = option{1}
Y :int = 1
X = Y // This compiles and fails in the context

```

> **[Comparable in Verse | Unreal Editor for Fortnite Documentation | Epic...](https://dev.epicgames.com/documentation/en-us/uefn/comparable-in-verse)**
>
> A subtype of any, comparable adds the requirement that any value of this type can be compared to any other value of this type.

To use ‘=’ operator, both sides should have same type.  
Optional type and non-optional type is not the same type. However it compiles.

Also in enum

```verse
X :?my_enum = option{my_enum.A}
Y :my_enum = my_enum.A
X = Y // This comiples and fails in the context

```

I used to create state as optional enum but sometimes I make a mistake comparing optional enum with non optional enum.  
Comparing non-optional and optional always fails. Does anyone know why this compiles?

I’ll share code so you can easily test

```verse
# Code for test
using { /Fortnite.com/Devices }
using { /UnrealEngine.com/Temporary/Diagnostics }
using { /Verse.org/Colors }
using { /Verse.org/Simulation }

my_enum := enum:
    A
    B

hello_world_device := class(creative_device):
    OnBegin<override>()<suspends>:void=
        loop:
            Print("Test Start", ?Color:=NamedColors.Blue)

            Tests := array:
                Compare0,
                Compare1,
                Compare2,
                Compare3,
                Compare4,
                Compare5

            for (Index -> Test :Tests):
                if (Test[]):
                    Print("Test {Index} is true", ?Color:=NamedColors.Green)
                else:
                    Print("Test {Index} is false", ?Color:=NamedColors.Red)

            Sleep(10.0)

    Compare0()<transacts><decides>:void= # Expect to be true
        X :my_enum= my_enum.A
        Y :my_enum= my_enum.A
        X = Y

    Compare1()<transacts><decides>:void= # Expect to be true
        X :?my_enum= option{my_enum.A}
        Y :my_enum= my_enum.A
        X = Y 

    Compare2()<transacts><decides>:void= # Expect to be false
        X :?my_enum= option{my_enum.A}
        Y :my_enum= my_enum.B
        X = Y 

    Compare3()<transacts><decides>:void= # Expect to be true
        X :?my_enum= option{my_enum.A}
        Y :?my_enum= option{my_enum.A}
        X = Y

    Compare4()<transacts><decides>:void= # Expect to be false
        X :?my_enum= option{my_enum.A}
        Y :?my_enum= option{my_enum.B}
        X = Y

    Compare5()<transacts><decides>:void= # Expect to be true 
        X :?int= option{1}
        Y :int= 1
        X = Y
        

```

---

<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:** [May 30, 2025, 1:19pm UTC](https://forums.unrealengine.com/t/why-comparing-optional-with-non-optional-compiles-well-and-always-fails/2534074/2 "2025-05-30T13:19:02Z")

</div>

That’s because they are different, a ?int and int are different.

Same reason while this will compile it will never be true  
 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/1/5/0/15037e22bd8571bcc33120d9541358257ae2adf9.png)

---

<div class="post-metadata">

**Author:** ![Konerds](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Konerds](https://forums.unrealengine.com/u/Konerds)\
**Post date:** [May 30, 2025, 2:38pm UTC](https://forums.unrealengine.com/t/why-comparing-optional-with-non-optional-compiles-well-and-always-fails/2534074/3 "2025-05-30T14:38:45Z")

</div>

Thanks, I understand it better after seeing the example. The comparison operator works even if the types are not exactly the same.  
I think it would be better to add some custom methods to compare explicit types.
