Get array index of a clicked object

Hi everybody, I’m making a simple project where you click on the cube, get the widget with three buttons with which you can change the color of the cube. I’ve set up everything and it’s working fine with one cube, but once I add more cubes it doesn’t matter which cube I’ve clicked on, the color will always be changing on the first one(or if I change the index value manually in the blueprint).

I figured out that the problem is in the Widget Blueprint where I reference the Cube

The circled value is the index of the Cube that will get it’s color changed. My question is how can I get the index of the clicked cube so that I can put it into variable that will automatically assign that index to the Cube reference in the Widget Blueprint where I’m changing the color of the selected Cube?

Why would you want the index of the clicked cube, and not just get the cube you are clicking directly?

I thought the only way for this was with Get All Actors node and then indexing them.

How do I get it directly?

Just use the node “get hit result under cursor by channel” (needs a controller reference), break the hit result, cast it to BP_Cube, save the output as a variable. Pass the variable to your widget and you’re done. If you need help with understanding casting, references or communicating with widgets you can check out these videos I created that will help you get a foundation for the things I mentioned. Specifically video #1 and #25 will be particularly helpful here.

I tried using this node and I don’t really know how to work with it. I tried all options from Break hit and I got the names of the Cubes I’m clicking on but I can’t use them as Index for GET since I need Integer. I also tried promoting them as Variable and calling them from the Cube Reference in the Widget BP and setting them as target but that didn’t work either.

So I don’t know how to make this work with my current set up. Here’s what I have.

Widget BP:

Cube BP:

276338-cube-blueprint.png

Here’s my try with the nodes you suggested:

Thanks for the tutorial recommendation, I’ve already watched them and they really helped.

Something like this

You don’t script this in the cube BP, notice I am using the controller and an input event “left mouse click” to find a “hit” under my cursor, it returns an actor reference if you clicked on one (in your case a cube), if the actor is a cube not the floor or sky or something else, then you save the reference as a variable. Now depending on your setup and how the widget is created will determine how you feed that reference to the widget.

I got it now. I started everything from scratch and created everything in Player BP. I referenced buttons in Player BP as well and then gave them OnClick there. It’s messy, but tomorrow I’ll figure out how to reference this in Widget BP.

Right now if I try to reference this Cube variable in the Widget BP I get nothing.
But at least it’s working in Player BP.

Thank you for your help.

This helped me so much I’ve been stuck for 2 days now

Thank you!!!