Passing custom data to a blueprint function from an event listener

I’m trying to pass custom data into a blueprint function. My current attempt looks like this:

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?

Thanks

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.

1 Like

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.

1 Like

Thanks, this looks like the right path to take. I am unsure of how to add the extra parameter to the event dispatcher.

The first part is easy enough.

You do not need indexing at all.

  • in the widget, create an additional Event Dispatcher and add inputs, pipe in the data into pins:

  • when you bind:

This is the data of the widget whose text changed. No need to look anything up.


Or add the widget itself as a signature:

  • in the widget:

  • when you bind:

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.

1 Like

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