I’m attempting to pass in the index for the current widget (from a ScrollBox), so that I can look up data associated with this widget. However, the Index value is always the last index of the for loop.
Can anyone suggest how I might be able to pass in each number?
Yes, of course it will be the last index of the for loop, as the for loop will keep iterating before the completion event gets invoked.
You could store “which worker was assigned” into a variable of some sort, and read it back when handling the event, but if you have the chance of starting more than one worker before handling the helper event, the second one will stomp on the first one.
Thus, it’s typically better to either do the work you need to do inline in the assignment, OR to put the code for handling event inside the actual worker selected, OR come up with some lightweight object that contains the (worker, index) data you need, and carry that forward.
I’d probably put the event in the worker, and/or make each worker know which index it is.
You add a variable WorkerIndex inside your menu ResearchItem, set it like in the image.
And add another input paramter for your event dispatcher to store the WorkerIndex in your custom event WorkerEvent.
Your Assigned Workers could be direct references to widgets. Although I feel this is set up a bit backwards. You generally do not want to contain game logic inside widgets. But it could work.
Can anyone suggest how I might be able to pass in each number?
The real question is, do you actually need the index? The widgets should have been notified on creation which index of the container they occupy and then retrieved with the above.
so that I can look up data associated with this widget.
If that’s all that is needed, we don’t need indexing.