Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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.

Product Version: UE 4.13
more ▼

asked Oct 05 '16 at 05:51 PM in Blueprint Scripting

avatar image

8 1 2 5

avatar image Diogobrc Oct 05 '16 at 09:51 PM

Hy Doug, 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?

alt text alt text

hud.png (72.9 kB)
error.png (52.7 kB)
avatar image Doug E ♦♦ STAFF Oct 06 '16 at 12:44 PM

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 PC 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).

alt text

alt text

actorref.png (107.0 kB)
widgetref.png (135.4 kB)
avatar image Diogobrc Oct 06 '16 at 01:30 PM

Thanks for the info, i did it!

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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.


Doug Wilson

more ▼

answered Oct 05 '16 at 09:11 PM

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question