# How do you assign a value to a map of structs?

**URL:** <https://forums.unrealengine.com/t/how-do-you-assign-a-value-to-a-map-of-structs/1301954>\
**Category:** Verse\
**Tags:** unreal-editor-for-fortnite, fortnite-creative, question, fortnite\
**Created:** [September 18, 2023, 3:59pm UTC](https://forums.unrealengine.com/t/how-do-you-assign-a-value-to-a-map-of-structs/1301954 "2023-09-18T15:59:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ululator](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Ululator](https://forums.unrealengine.com/u/Ululator)\
**Post date:** [September 18, 2023, 3:59pm UTC](https://forums.unrealengine.com/t/how-do-you-assign-a-value-to-a-map-of-structs/1301954/1 "2023-09-18T15:59:36Z")

</div>

It seems you can’t assign a value to a map of structs because the compiler thinks you want to modify the interior of the struct instead of replacing the struct wholesale in the map:

```auto
example_struct := struct:
  something: int

example := class:
  ExampleMap: [int]example_struct := map{}

  Test():void =
    if(set ExampleMap[0] = example_struct{something:= 0}):

```

The above code will error on the last line with `The assignment's left hand expression type 'example_struct' cannot be assigned to(3509)`. It’s an odd error, since the struct does not exist yet in the map, seems like a type system problem.

Any ideas how to work around this?

---

<div class="post-metadata">

**Author:** ![Ululator](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Ululator](https://forums.unrealengine.com/u/Ululator)\
**Post date:** [September 18, 2023, 4:07pm UTC](https://forums.unrealengine.com/t/how-do-you-assign-a-value-to-a-map-of-structs/1301954/2 "2023-09-18T16:07:13Z")

</div>

Ah, the error was rather confusing, but the actual problem here is that the Map is defined as constant and not `var`, this works:

```auto
example_struct := struct:
  something: int

example := class:
  var ExampleMap: [int]example_struct := map{}

  Test():void =
    if(set ExampleMap[0] = example_struct{something:= 0}):

```

---

<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:** [October 18, 2023, 4:07pm UTC](https://forums.unrealengine.com/t/how-do-you-assign-a-value-to-a-map-of-structs/1301954/3 "2023-10-18T16:07:52Z")

</div>

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