Populating data from data table into a widget on click. (How to save name of actor on click?)

A part of my game will be players being able to click on a planet and being able to view data about the planet like this (obviously, WIP):

On clicking a planet, that blue-ish UI widget on the left pops up. (This part is coded in the ‘CelestialBody’ blueprint which is a class I made so planets can orbit etc.) The actual values are being populated by a data table/data structure that I made. I have dozens of planets I have planned. I didn’t want to make an individual widget for each planet so I think this was the right route to go.

Here’s the blueprint for the widget below. (Note that this structure is in the UI widget… but I can copy/paste the same code logic into the ‘on click’ celestial body blueprint too, if that helps:)

However, as you can see, I had to manually hard code the row name to 1, which is corresponding obviously to the first row of the data frame.

What I want to do is somehow input a value somewhere so that if I click on planet 1, shows planet 1’s data in the widget… for planet 2, it would populate planet 2’s data.

I’m kind of new to Unreal and the original way I thought I could do that would be to somehow retrieve the name of the actor that was clicked… but I’m having difficulty figuring out how to do that. The idea would be to name the actor the exact same name as the row number so the data would be populated that way.

I guess I’m coming here to ask:

  1. Conceptually does this make sense?
  2. If so, how the heck do I reference the clicked actor? I found some info on the “LastThingClickedByChannel” or whatever but couldn’t quite figure out how to save that as a value to pass to the data frame.
  3. If not, how would you do it?

Thanks all!

So, on your planet where you have your click event (onPressed, onReleased, onClicked or whatever), you can have a variable on your planet that is of the name type (The Row ID is of name type), you can then pass that variable to your widget and have the widget pull the DataTable Row ID using the Name it received from the Variable. You can name a Row ID anythign a Name variable can be. Or, if it works out how you setup your game,

I think maybe where your problem is arising is that you are doing this on a construct event, which is not letting you pass a variable through to your widget. You woul need to create a function or custom event that you can call on widget to have widget either update its information, create the widget and have the name variable exposed to on spawn. You could also have a reference to your widget on the planet, have the plnets set the structure variable on the widget, and the widget would bind the information in the variable, which it would then auto update whenever that variable changes, but if you have an intense game, it takes up processes because it checks every tick.

I personally would probably have the widget set a reference variable in the GameInstance when it is created, then your actors can access the variable from GameInstance to get the reference to the widget, set the widget variable ( a struct like you have now), set the widget to visible (if needed) and then have logic in the widget for breaking apart the data struct to set its own child widget text boxes ect. This way, your planet can easily access its own name variable to set the struct with desired info from Data Table before sending to widget.

Thank you very much for the response.

Yes – in your first paragraph – that’s exactly what I’m trying to do and what I’m asking about. I just don’t know how to do it haha. What function am I looking for? What do I need to branch off of after the click event? I have the name variable for each planet (CelestialBody_ReferenceName) set up, but what function/stuff do I need to input into the blueprint to get that? That’s what I’m literally asking for and I feel like I’m so close but so far! I just need to know how to get that!

Ok… about 5 minutes after posting this response I figured it out. I just had to drag out the “Get CelestialBody_ReferenceName” bubble. Don’t know why I didn’t think of that before. Ouch.