How to pass a Int Var in Actor to HUD

Hi, Im new to Unreal, im trying to make a 2d Click game, for this i create an Actor and when i click this actor, it add 1 to my var, this is working, the problem is i trying to show this var in the HUD, but a can’t do, I searched tutos but its only for players character, never to actor, so im bit lost. Anyone know how to do it? in the game i dont have a player, since its only clicks, so i think this might be the problem too.

Hey Diogobrc-

One way you can do this is to use the Get All Actors of Class node in your widget to find all instances of your actor in the level, then use a Get node from the output array to find the specific instance of the actor required. The issue with this method is that if you have multiple instances of the actor in the level you will have to determine which one you are getting from the array.

Another method would be to, when the actor is clicked, pass the int from the actor to a corresponding variable in your Controller. You can then use the Get Player Controller node in your widget to access the corresponding variable which should contain the value from the actor.

Cheers

Hy , thanks for Reply, i Tried, but i have some questions, How do i set the variable in my controller? i create a global var in the Controller, but when i try to set in the actor i dont know how to set up

This is the Actor Blueprint, the var HP_Controller is the var in my controller, whats the target(Alvo)? sorry, im brazilian and my unreal have some itens in portuguese, i dont know why. i add the blueprint in my HUD too, I need to change the HP var to HP_controller right?

Thanks for the info, i did it!

In my setup I first got a reference to the player controller inside the actor blueprint with Get Player Controller. After a cast to ensure that this was the player controller blueprint with my variable I set it as a variable for easy reference later. I use the reference to access my int variable in the player controller and increase it.

Then in the widget blueprint I do a similar first step of getting a reference to my player controller and setting a local reference variable. The only difference is that I use a “Get Player Character” to access its controller. I then again use my reference to access the int variable inside the widget and print to screen. Here are a couple of screenshots to illustrate what I’m saying (the first is my actor blueprint and the second is my widget blueprint).