the for each loop is not working correctly. For some reason, it repeats not as many times as the elements in the array, but exactly 2 times more.
Ok you need to try a few things.
- Check you are not accidentally adding the array elements twice to the array
- Check you are not entering the function/event twice
Check both by putting a stop (Breakpoint, highlight the node hit the F9 key on PC) on the for each loop and check the contents of the array , then iterate through til it ends and see if it calls this event twice.
Let me know if you spot anything, never had a for loop error like this unless its been a code issue myself.
in general, as I understand it, the Construct and Pre construct events are run twice, that’s why the cycle was run twice.
So that is your answer to why.
If you don’t want it to perform the code twice you need to consider a DoOnce node or some sort of check to ensure the code is only ran the first time.
PreConstruct and Construct can be run any number of times there is no guarantee it will only run once or twice.
You need to use “On Initialized” when you want to ensure it only happens once per UserWidget instance.