Multiple Instances of a Widget that share a variable but have different values

I have a widget that i create with a ForLoop 4 times, that widget contains a “Self ID” Integer variable which i increment on event construct. The widget also has a button which is hooked up to a PrintString that displays the “Self ID” value. I thought since i am creating 4 different widgets with my ForLoop, each instance of it would have a different integer as their “Self ID”, however all 4 instances return a value of one. Can someone explain what i am missing? It seems like that the event construct is only firing once regardless of the amount of times my loop is running. Thank you!

1 Like

Variables are not shared, each instance contains its own variables.
Every time you create a widget, the created widget starts with Self ID = 0 (default value), then event Construct runs on that instance, increasing its value to 1.

To achieve what you want, you should add a counter variable in the blueprint doing the ForLoop. Every loop, create new widget, increase counter by 1, and assign the created widget’s SelfID to the current value of the counter.

3 Likes

Dude… Thank you so much! I’ve been at it for hours. Just tested it and works perfectly, thank you!

1 Like