# Variable property inside Struct

**URL:** <https://forums.unrealengine.com/t/variable-property-inside-struct/1335923>\
**Category:** Verse\
**Tags:** unreal-editor-for-fortnite, fortnite-creative, question, fortnite\
**Created:** [October 17, 2023, 7:12pm UTC](https://forums.unrealengine.com/t/variable-property-inside-struct/1335923 "2023-10-17T19:12:02Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Portine](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/portine/32/1182274_2.png) [@Portine](https://forums.unrealengine.com/u/Portine)\
**Post date:** [October 17, 2023, 7:12pm UTC](https://forums.unrealengine.com/t/variable-property-inside-struct/1335923/1 "2023-10-17T19:12:02Z")

</div>

So, I have the following code for a struct that is organized inside a map variable:

```
currency_properties := struct:
    Type : currency
    Value : int = 0
    GainPerSecond : int = 0

var Currencies<private> : [currency]currency_properties = map{}

```

And trying to set these values in another function:

```
SetValue(Currency:currency, Value:int):void=
    if(CurrencyProperty := Currencies[Currency]):
    set CurrencyProperty.Value = Value

```

But it’s throwing me the error:

```
The assignment's left hand expression type `int` cannot be assigned to(3509)

```

Well, fair enough, right? I don’t have the ‘var’ expression in the ‘Value’ property inside my struct.  
But it also doesn’t work when I put it there, throwing me a new error:

```
Structs may not contain mutable members.(3607)

```

I can see a workaround by instancing a new struct every time I’ll change a value, but is there no better way to do this? Am I missing something about structs?

Thanks in advance for any support!

---

<div class="post-metadata">

**Author:** ![SeedohFN](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/seedohfn/32/720959_2.png) [@SeedohFN](https://forums.unrealengine.com/u/SeedohFN)\
**Post date:** [October 17, 2023, 7:50pm UTC](https://forums.unrealengine.com/t/variable-property-inside-struct/1335923/2 "2023-10-17T19:50:11Z")

</div>

The way you mention at the last is the correct and the only way to change a struct. As you already knew, struct cannot have mutable data inside it. Check the documentation about [Struct](https://dev.epicgames.com/documentation/en-us/uefn/struct-in-verse) for more info!

---

<div class="post-metadata">

**Author:** ![LoPing](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/loping/32/737300_2.png) [@LoPing](https://forums.unrealengine.com/u/LoPing)\
**Post date:** [October 17, 2023, 7:51pm UTC](https://forums.unrealengine.com/t/variable-property-inside-struct/1335923/3 "2023-10-17T19:51:25Z")

</div>

In my experience you need to treat is as initializing a new structure each time, but if anyone has a better way, I’d love to hear it.

Verse is the only language I know with this issue, it seems like they are so busy putting in cool stuff, that basic stuff is neglected.

---

<div class="post-metadata">

**Author:** ![Portine](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/portine/32/1182274_2.png) [@Portine](https://forums.unrealengine.com/u/Portine)\
**Post date:** [October 17, 2023, 8:00pm UTC](https://forums.unrealengine.com/t/variable-property-inside-struct/1335923/4 "2023-10-17T20:00:18Z")

</div>

Thanks! I will solve it this way then.

---

<div class="post-metadata">

**Author:** ![Portine](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/portine/32/1182274_2.png) [@Portine](https://forums.unrealengine.com/u/Portine)\
**Post date:** [October 17, 2023, 8:01pm UTC](https://forums.unrealengine.com/t/variable-property-inside-struct/1335923/5 "2023-10-17T20:01:14Z")

</div>

I feel that…  
The basic stuff are so basic and intuitive that if baffles me that they aren’t available yet.

---

<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:** [October 17, 2023, 8:15pm UTC](https://forums.unrealengine.com/t/variable-property-inside-struct/1335923/6 "2023-10-17T20:15:26Z")

</div>

I personally never use `structs`, using `class` (or `class<concrete>` if you want to expose data) allows you for much more.

Though, `non scalar` values don’t seem to expose well at the moment (see [Nested concrete classes @editable properties gets reset everytime](https://forums.unrealengine.com/t/nested-concrete-classes-editable-properties-gets-reset-everytime/1286781))

---

<div class="post-metadata">

**Author:** ![SeedohFN](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/seedohfn/32/720959_2.png) [@SeedohFN](https://forums.unrealengine.com/u/SeedohFN)\
**Post date:** [October 17, 2023, 8:18pm UTC](https://forums.unrealengine.com/t/variable-property-inside-struct/1335923/7 "2023-10-17T20:18:04Z")

</div>

Alternatively, you can create a class and create methods that affects the variables you have if you wish so. In this way you don’t have to instance a whole new class to change one variable

---

<div class="post-metadata">

**Author:** ![Portine](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/portine/32/1182274_2.png) [@Portine](https://forums.unrealengine.com/u/Portine)\
**Post date:** [October 18, 2023, 2:19pm UTC](https://forums.unrealengine.com/t/variable-property-inside-struct/1335923/8 "2023-10-18T14:19:02Z")

</div>

@im_a_lama and @SeedohFN  
I didn’t think of using a class to solve it, it worked perfectly and it’s exactly what I wanted.  
Thank you very much!

---

<div class="post-metadata">

**Author:** ![system](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/1/3/713c9d3f58553f0de89543d76a8a3a2779dc9fa4.png) [@system](https://forums.unrealengine.com/u/system)\
**Post date:** [November 17, 2023, 2:20pm UTC](https://forums.unrealengine.com/t/variable-property-inside-struct/1335923/9 "2023-11-17T14:20:00Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
