# Updating array of struct

**URL:** <https://forums.unrealengine.com/t/updating-array-of-struct/423545>\
**Category:** Blueprint\
**Tags:** add-variable, update, unreal-engine, Blueprint, question\
**Created:** [April 25, 2018, 11:28am UTC](https://forums.unrealengine.com/t/updating-array-of-struct/423545 "2018-04-25T11:28:56Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![t0msk](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/t0msk/32/614638_2.png) [@t0msk](https://forums.unrealengine.com/u/t0msk)\
**Post date:** [April 25, 2018, 11:28am UTC](https://forums.unrealengine.com/t/updating-array-of-struct/423545/1 "2018-04-25T11:28:56Z")

</div>

Hello,

I have array of struct and I would like to ask you what is correct way to update specific variable on specific index with new value.

You can see my blueprint script below, and you can see that I get element from array with specific index, then I break it and make from it new element (changing only 1 variable) and inserting into array on same index.

Just want to know if there is “cleaner” way to update array with new values.

 ![](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/2/0/220811a5de0f91b1bc6d12ac2afe6cb585b82319.png)

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [April 25, 2018, 11:46am UTC](https://forums.unrealengine.com/t/updating-array-of-struct/423545/2 "2018-04-25T11:46:17Z")

</div>

Like so:

 ![238761-capture.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/1/e/2/1e21242d98225fb698eb6fec9b3833e5a50c039a.png)

The unexposed pins remain unchanged. BUT!

When you use _arrays_, _loops_, _get_ they fetch _copies_ of the struct rather than _references_ (notice the _dot_ vs the _diamond_ pin symbol in the pic above). This means that you need to be extra careful and always push in the altered data back into the container it came from:

 ![238762-capture2.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/c/e/0/ce06eee6be185901a6cda2baab16a0c316cc24ee.png)

---

<div class="post-metadata">

**Author:** ![t0msk](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/t0msk/32/614638_2.png) [@t0msk](https://forums.unrealengine.com/u/t0msk)\
**Post date:** [April 25, 2018, 1:43pm UTC](https://forums.unrealengine.com/t/updating-array-of-struct/423545/3 "2018-04-25T13:43:20Z")

</div>

So diamond is something like pointer in C language right? It contains a address of variable inside memory and circle is just copy of value, right?

This is what I want (image below), as you can see, I loop throught whole array and spawn Actors, then I only want to update reference in my struct to newly created Actors and others values leave the same.

But if I run this, then my apps stop working, because I insert new element into array (endless loop)? I don’t think that there is endless loop, because I insert new element into array at current index, but **ForEachLoop** should jump to another index in array, no?

 ![](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/d/e/6de32beb7bb45accebd70006015a560900af28a9.png)

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [April 25, 2018, 1:57pm UTC](https://forums.unrealengine.com/t/updating-array-of-struct/423545/4 "2018-04-25T13:57:22Z")

</div>

> So diamond is something like pointer  
> in C language right? It contains a  
> address of variable inside memory and  
> circle is just copy of value, right?

Pretty much, yeah.

- 
  - 

- at the moment, you have no array to insert structs into - nothing is hooked up to the Insert node’s array pin (you either updated the image or I went blind)

- insert will push other indexes each time it’s called - you will end up with updated structs in front and old ones in the back of the array - the array will double in size. That’s unless _Elements_ is a brand new, empty array with no data.

- use _SetArrayElement_ (as seen in the pic attached in my previous post) - this will simply replace the array element with the updated one

- the top bit of my pic above seems to be precisely what you need, _Set Members In_ struct is key, here, just expose _RefCube_ and you’re good to go. No need to break/make structs like that.

---

<div class="post-metadata">

**Author:** ![t0msk](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/t0msk/32/614638_2.png) [@t0msk](https://forums.unrealengine.com/u/t0msk)\
**Post date:** [April 25, 2018, 3:22pm UTC](https://forums.unrealengine.com/t/updating-array-of-struct/423545/5 "2018-04-25T15:22:22Z")

</div>

Thank you 🙂

So I ended with something like this, so **Set Member** will just change **Ref Cube** and another values leave untouched, right? 🙂

 ![](https://d3kjluh73b9h9o.cloudfront.net/original/4X/f/9/a/f9a1768ced920716a2d5ea09d51c3b201df9623f.png)

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [April 25, 2018, 4:45pm UTC](https://forums.unrealengine.com/t/updating-array-of-struct/423545/6 "2018-04-25T16:45:04Z")

</div>

Yeah, that looks about right. Should work.

---

<div class="post-metadata">

**Author:** ![XxNotAGamerxX](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@XxNotAGamerxX](https://forums.unrealengine.com/u/XxNotAGamerxX)\
**Post date:** [May 23, 2023, 3:32am UTC](https://forums.unrealengine.com/t/updating-array-of-struct/423545/7 "2023-05-23T03:32:47Z")

</div>

Can you please help with a similar question?

1. How do I Set all indexes of an Array, to a Certain INT value, and in the Construct Graph,
2. 
  - but only once? (Only when the Certain INT value changes in Editor - in original BP or BP Instance copy.)

Meth 1 and 2 code is not working when connected to Construct node:

 ![UE4 b How do I to set all Array indexes to a certain value at Construct](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/f/d/7fd06fa2e29df8213dc15fc206d74b6df4c348b2.png)

I have two variables. An INT (“Override”), and “Array” of INTs.  
I want an easy way to update each INT in the “Array” to all be the “Override” INT #.

Q2: But only change Array values once in Construct: meaning if in Editor, I manually change “Override #” from 1 to 2, then Array updates to all have 2s.

But if I now I manually change index 1 of “the Array” to a value of 3 (and “Override #” is still at 2), then the Construct code will not trigger to reset all the Array to #2.

(Im not sure of the logic in Construct, if I need to add a Bool, to turn on/off parts of the Construct code til I want it run. Or if I can rely on just not changing the Override Int, and thus that code will not run? But the Meth 1 code is not making the Array update at all, when I change “Override” to 2.)

Please help, ty.

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [May 23, 2023, 7:31am UTC](https://forums.unrealengine.com/t/updating-array-of-struct/423545/8 "2023-05-23T07:31:52Z")

</div>

The script if fine, I am not 100% sure I understand the issue, though; but hear me out:

The **C** onstruction **S** cript runs :

- when actor is spawned; that exposed variable will be updated with no additional script:

![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/5/5/7/557271769ed145f775fc697b4db747d4dcf4c68c.png)

- when an actor is placed and / or dragged in the scene
- when a Child Actor Component instantiates an actor
- when actors’ data gets updated - this can be done by flagging variable as `Instance Editable`:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/6/0/66010bea4a8606e4c5fae8dab4c6b84070036414.png)

If you do the above, the actor fill fetch data from this variable, no matter what you set its value in BPs.

* * *

Since this is what I believe you’re after, in your case:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/8/3/8/8382231cb6bd151f1d489ccca56e9f06da725b13.png)

![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/1/d/e/1dee690d812991d05eddd48969c467580dc48005.png)

As soon as you hit enter, every index of this array will have 2 assigned.

* * *

- sometimes you do not want to run the _entire_ CS or need to run something unrelated to the CS, you can use Editor Callable Custom Events:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/0/9/60985b79c553c68b3d1634a0b15ee3ed2807886d.png)

Here I assign a value to an array inside the actor. This has nothing to do with CS, but simply updates the instance of the actor.

- there are also EUWs - Editor Utility Widgets. They can do the above but the script does not belong to the actor. Let’s say you want to select 14 / 20 actors in the scene and update their arrays all at once to some specific values. Or make them trace their surrounding. The script does not need to clutter the affected actor and can live in a specialised widget that can be only run outside of PIE.

- the Construction Script _does not_ run for actors placed in the scene when the game starts

---

<div class="post-metadata">

**Author:** ![XxNotAGamerxX](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@XxNotAGamerxX](https://forums.unrealengine.com/u/XxNotAGamerxX)\
**Post date:** [May 23, 2023, 8:32am UTC](https://forums.unrealengine.com/t/updating-array-of-struct/423545/9 "2023-05-23T08:32:46Z")

</div>

Thanks for your time listing all those options and the graphics 🙂

> [@Everynone](#):
>
> Since this is what I believe you’re after, in your case:
> 
> ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/8/3/8/8382231cb6bd151f1d489ccca56e9f06da725b13.png)

I checked that my vars are Instance Editable. But in BP editor (not BP Instance), does your Array update to 3, 3, 3 - if you change “Item” to 3? Because mine does not.

 ![UE4 Construct bugs](https://d3kjluh73b9h9o.cloudfront.net/original/4X/8/9/8/898990e52dc713a8324a9f1914bf9dce887d384f.png)

My Array only updates if I _edit in the Level_, my “Item” Int of a BP Instance (copy).

> “The **C** onstruction **S** cript runs :” “when actors’ data gets updated - this can be done by flagging variable as `Instance Editable`”

- Is not _editing a Var in the BP Editor (not Level), a condition_ to make Construct fire?
- (It works when I change a droplist Var (in Editor), and I have CS that instantly works to change the displayed Mesh - while in BP Editor AND in Level \> BP Instance. But this Array Var is only updating in BP Instance (edit in Level).)

And I have some bugs that may be complicating my testing.  
Bug1: the Orange-animation Construction-line fails to display weekly, when I press Construct (and I know the line worked before). (Reporting in another thread.)

Bug2: I think my asset is corrupt. My first test Array had 10 indexes, but only 2 show in the BP Instance, after compile/save/restart Engine. So I made a new Array. Now all indexes show.

Limitation or bug 3: But editing in Level \> BP Instance, I can change “Item” INT = 2, but can no longer change the individual indexes of the Array values. They get locked on 2. (Perhaps because the CS autofires when I type 5 into the Array index, thus the INT 2 pushes a CS override (upon the Array) back to 2?)

> [@Everynone](#):
>
> Editor Callable Custom Events:

Thus thank you for teaching me about this. Perhaps I want to set the Int/Array with this button thing. So I will investigate this. Ty 🙂

- (My goal was to save time, Set 10 indexes of an Array to value = 5, instead of having to set them all. But I also want the option to manually change a few of them after the bulk Set.)

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [May 23, 2023, 8:47am UTC](https://forums.unrealengine.com/t/updating-array-of-struct/423545/10 "2023-05-23T08:47:40Z")

</div>

> [@XxNotAGamerxX](#):
>
> But in BP editor (not BP Instance), does your Array update to 3, 3, 3 - if you change “Item” to 3? Because mine does not.

It does not and it should not. So you’re expecting:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/5/d/d/5dd36274778bb24104d4adff548686497288a55b.png)

The array to update here, right?

> Limitation or bug 3: But editing in Level \> BP Instance, I can change “Item” INT = 2, but can no longer change the individual indexes of the Array values. They get locked on 2. (Perhaps because the CS autofires when I type 5 into the Array index, thus the INT 2 pushes a CS override (upon the Array) back to 2?)

I’d say it is neither and working as intended. It’s just not working the way you need it, which is fair. Perhaps you could ask the CS to do more work:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/c/b/9cb3c00c2b4f117d9240dbf00ae9d94ec7ea5f66.png)

Set all to Item, and then set an individual Index to Another Item. Could this work?

---

<div class="post-metadata">

**Author:** ![XxNotAGamerxX](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@XxNotAGamerxX](https://forums.unrealengine.com/u/XxNotAGamerxX)\
**Post date:** [May 23, 2023, 7:11pm UTC](https://forums.unrealengine.com/t/updating-array-of-struct/423545/11 "2023-05-23T19:11:49Z")

</div>

Thanks for your reply on issue 3.

> [@Everynone](#):
>
> So you’re expecting… The array to update here, right?

Yes. That is what I need.

- I tried your pic, and I can manually change a specific index at “Complete.” (Fixes one issue, but I still can’t update ALL Array values while in BP graph Editor \> after CS runs.)

- And I setup a Call-In-Editor Event. But I can only use the button in Level/World Editor???  

- So none of these are solutions. (I’m prototyping in BP code, and need to see the changes live when CS runs, before I ever place the Actors in Level. Easier to stay in the same Graph window than switch to Level tab.)

So back to my issue, **I don’t understand why cant CS update all values in an Array - to a specific INT - while in BP (Graph) Editor?** _How can this be working as intended [UE4.27] when I can live-update other types of Vars with CS - but not Arrays?_

- All 3 of these methods fail. Do you know a solution? Thanks for your time.  
 ![UE4 2 How do I to set all Array indexes to a certain value at Construct](https://d3kjluh73b9h9o.cloudfront.net/original/4X/0/8/f/08f905a944e4d87d7c60078e1367bf44d71969c8.png)

---

<div class="post-metadata">

**Author:** ![XxNotAGamerxX](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@XxNotAGamerxX](https://forums.unrealengine.com/u/XxNotAGamerxX)\
**Post date:** [June 1, 2023, 4:07am UTC](https://forums.unrealengine.com/t/updating-array-of-struct/423545/12 "2023-06-01T04:07:19Z")

</div>

Hi, Im back if you can please help. Ty

1. Can Construct (in Editor) really **not update certain variables** like **Arrays** (this thread - I gave up trying to update the Array),
2. or **MAPs** (new thread)? (CS works on changing Meshes and Light colors - but not Arrays/Maps?) This [bug?] is paralyzing my progress.

> [@Why cant I Set/Update a MAP variable in Construction script?](https://forums.unrealengine.com/t/why-cant-i-set-update-a-map-variable-in-construction-script/1185231):
>
> UE4.27 Can Construct really not update certain variables like Arrays or MAPs? (It works on changing Meshes and Light colors.) How can I Set/Update a MAP variable in Construction script? - these nodes are not working: I have a complicated Function that is used in Event and Construct - in CharBP and pickup Actors. So I made an external Function asset (s…

---

<div class="post-metadata">

**Author:** ![High-Orbit-Games](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@High-Orbit-Games](https://forums.unrealengine.com/u/High-Orbit-Games)\
**Post date:** [May 11, 2025, 1:37pm UTC](https://forums.unrealengine.com/t/updating-array-of-struct/423545/13 "2025-05-11T13:37:41Z")

</div>

I greatly thank you 7 years later. ive been doing the Set Member without set array element
