Communicating Between Pawn, HUD and Actor Blueprints

I can get my HUD widget to talk to my actor blueprint… but I cannot get either to talk to my pawn blueprint. I will detail my steps below. All my variables are set to public. I am not using any templates. In game modes, my default pawn is the pawn blueprint I am trying to access. (not sure if that makes any difference at all).

This first part works fine for me… I will just detail all the steps so you know exactly what I am trying.
To get my actor blueprint to talk with my HUD_Widget I did this:
In my actor blueprint, on EventBeginPlay I drag off → create Hud_Widget, then I drag of the return value and promote to variable (I can also just create this variable in the widget blueprint and call the reference), I name the variable Hud_Ref2. I then set to viewport and go about my business setting all my variables in both blueprints for initialization. Pic01

Now I go back into my Hud_Widget, I have a button I want to do something. Under ‘On Clicked’ I go into event graph and create an event dispatcher named Teleport_Selected. I drag off the ‘on clicked’ and call ‘Teleport_Selected’ Pic02

If I now go back into my Actor Blueprint I can get it to do whatever I need. If I want something to happen when the button is pressed, I drag off the event tick (if I must) → ‘BindEvent to Teleport_Selected’, then create a Custom Event and go about my business. Pic03

And if I ever want a variable from my HUD_Widget, I just put the reference in and ‘get’ or ‘set’ whatever variable I want. Pic04

I can display scores, display lives, make progress bars fill, I can make my static mesh (the Actor blueprint) move depending on which button was pushed in the game. I can make the game end and change to a start menu. - Life is great and I feel like I know what I am doing.

Then I try to do the same for my Pawn Blueprint and it won’t work. I start with a very simple variable and print string.
At first I just tried to create a new reference to the HUD_Widget like I did with my actor. I kept getting the ‘access none while trying to read property error.’ I realized the only difference in the actor and pawn blueprints is at EventBeginPlay on my pawn I never did anything. So I set it up exactly like I did in pic 1 except I don’t ‘add to viewport’ since it is already there. (If I do add to viewport my HUD stops working, I imagine because an empty instance is on top of it now?). Now this made my errors go away… and this is the only instance I can access any information from the other blueprint. Pic05

I created a variable string named ‘test’ in the HUD_Widget blueprint. I set the default value to “not set”. Now if I start my game it will print that string one time. If I go back into HUD_Widget and change the default value of test string to “set” and restart the game… it will print it with the correct value so I know I am getting close now.

This is where my problem starts…
If I try to execute a custom event off a button set exactly like the actor blueprint… it doesn’t do anything. If I call my reference and try to ‘get’ or ‘set’ any variables… it also doesn’t do anything. It doesn’t give me any errors like ‘access none’ unless I leave out the bit from the EventBeginPlay. It doesn’t crash or prevent anything further down the chain from executing… it just acts like an empty wire basically. Pic06

At this point I am expecting it to print the variable ‘test’… every time I hit the teleport button… I have tried it all ways. I have tried referencing the Pawn and pulling to the HUD and vice versa. I have tried custom events, I tried custom events not tied to other blueprints (although I was pretty certain that did not matter). I tried it with and without the ‘get player controller’ connected to the Hud_Widget at EventBeginPlay. I tried casting before referencing but it mostly gives me the blue ‘unnecessary’ semi error.

Where am I going wrong?? What am I not understanding about casting? Any Help would be much appreciated.

Hey there, first of all why is the actor creating the widget? Second, doing a bind in the tick is a bad idea, you should do that once like on begin play after you have set Hud Reference 2. Finally, if the pawn you are trying to communicate on the widget is the “player” then you dont need event dispatchers, if you execute Get Owning Player Pawn on the widget it will give you a direct reference.

well…

imagine I created a basketball game.

The ball is the actor. And everything about the game revolves around the ball so to start that is where most of my code is. The pawn could be considered the player. (imagine there are no teamates… just the one pawn, maybe later two)

Although I am a bit confused on that (why an actor is creating the widget)… I partly lied… When i start the game I am in my level… when that game ends… then it loads the start menu… originally I tried setting the default level to the menu… but when I tried to load my level it wasn’t working… I realize I will have to straighten that out… but for now I am still stuck on the basics. - probably because that is how I Frankensteined 8 tutorials all using 1st or 3rd person templates and was only way i could get the hud and ball to talk. lol.

I do try to avoid using the Tick like it has a disease. For now I am simply using it to fire off an event since there is not much else in there - just to test things.

That last bit is where I am confused. I mostly won’t need event dispatchers for the pawn… I am just trying to access variables but i can’t other than reading default values at start. I just dont understand what the difference is to the HUD between the Pawn and the Actor. I get that one is controllable.

I would like to make a speed meter based on how fast my pawn player is moving or something along those lines…

and on the flip side… if a variable changes in my HUD… I would like it to make the pawn do something… spin, get faster, etc. something along those lines.

awe yeah… that did it… ill post some pics soon for others… I’ll add your name to the default High Scores you sexy beast!!!

Good to know :slight_smile: Please mark the question as answered. As a side note you should create the hud widget on the player controller begin play, because that is the common part whether you have 1 or 10 players.

Man, thanks so much, I was stuck on that for days. If it makes you feel better… I have not had to use my event tick yet. I always try to find a way to avoid it. And thanks for reminding me to move whatever Custom Events I did have from the EventTicks to the EventBeginPlays.

Where I was going wrong was what I was plugging into the object type whenever I would cast to my Pawn. Initially, I tried to make a reference to the Pawn… just like I made a reference to the widget in the Actor, (only I didn’t promote it from something… I just went in the HUD_Widget and created the variable, found the pawn under object types, and named it Pawn_Ref1). That is where I would get errors. If I left it blank it said error, If i put the pawn reference I just made it would tell me I didn’t need it… which I understood (I already knew what it was since I had the reference).

I mean, I still don’t see what the difference is between the variable reference I created is and the ‘get owning player pawn’ - since they both point back to the same blueprint or object in a sense… but I suppose in 6 months I will, lol.

Anyways… This is what I was trying…

Pic07
Pic08

Pic 8 Is what I was talking about… I didn’t know what to put in object. If I left it blank, error and if I put the reference I made it said it already knew it was that.

And this is what made it work thanks to Xlar8or

Widget
Pic09

Pawn
Pic10

Now as Soon as I star the level it prints the string over and over… The variable “Test_Bool” is stored in the Pawn Blueprint. Every time I click the button on the widget it toggles the boolean and my print string changed from false to true or true to false.

I’m not sure I even need the stuff at the event begin play on the Pawn now? Not if I’m using the Widget to act right? I still haven’t tried to go the other way… have the pawn set the widgets variables but I am not sure I need to.

Thanks Again so very Much!!!

Awesome, will do… how do i mark it answered… looking everywhere

You have a check mark next to my first answer, below the upvote count (currently at 2).

I still have a couple questions if you would be kind enough… and I will post a new question if you prefer.

So… As you pointed out, I should make the Pawn create the HUD and not the Actor.

If I take the CreateWidget out of the EventBeginPlay on my actor… I can’t get the two to talk anymore. I feel like I could fix the bindings by casting to my actor from the widget, like from the ‘on clicked’ like you showed me with the Pawn, although I’m not sure what to substitute with the ‘get owning player pawn’ for the actor…

But before I go through that I noticed if I just keep it in there, set the variable, then remove from parent… everything works…

So my question is technically, what am I doing?

Like when two blueprints Create a Widget

Is it making 2 widgets right on top of each other and only ‘showing’ the one I add the "set to viewport’ with?

I feel like that is… so then I wonder… How come I cannot just replace the ‘CreateWidget’ at the EventBeginPlay, with a cast to widget, or a set variable (reference to widget)? and If I can cast to widget… what do I plug in the object type? Tried player controller, owning pawn, reference to widget, If i reference the actor it says ‘doesn’t inherit from actor’.

casting makes sense to me on an overlap. but that’s about it. I feel like on an overlap… you just cast to something… to see if that is what overlapped… the object type is itself… so it makes sense. If it is that thing… then it will do whatever you connect to the execute pin… and if it’s not that thing it will do whatever you connect to the cast failed pin.

But when I make a blueprint cast… object screws me up because I always get the… such and such doesn’t inherit from this object… so then I think… ok it wants a reference to the only other object I am referencing here, so I plug that in and get the blue… ‘I know I am myself’ error.

I suggested that you should create the widget on the begin play of the player controller, not the pawn. I’m saying this because the player controller represents the players intent in the virtual world, when you have multiple pawns that could be possessed overtime, its better to just create the hud on a place that you know is always the same. You can access the pawn using the Get Owning Player Pawn inside of the widget, so you’ll get a reference for the currently possessed pawn. Some images would help me understand better what are your doubts.

That makes sense. My actor is so close to being the constant in the game but a player controller will always be there. Anything else you think I might overlook go ahead and blurt it out. I do at least always run with stat fps on to avert catastrophes. My 2D Render was SOOOO coool. lol.

just to be clear…

I can control a pawn directly with a keyboard or joystick… but NOT an actor?

I need an outline of how to control pawns… doesn’t have to be super in depth.

like
A. make a controller (or controllers)
b. set the camera here
c. give control over using this
d. don’t forget this.
e. everyone gets this part wrong…
f. to change back do this…

In the end I want to make 1 input move 2 pawns at the same time (sharing a camera.)
and then a little later, I want to change from that setup… to a 3rd pawn with a different camera for a few seconds… and then change back to the original setup.

If 1 input can’t move both pawns is ok if it could at least be the same joystick ie left analog stick controls 1 unit, right stick controls the other.

At the very least I just need to know how to switch between 2 pawns with their own camera’s. (not being used at same time.)

i was trying to make sense of this…

and this

but like i said I’m clueless.

This video helped a bit… If I cant figure it out I"ll post a new more specific question and then link you to it or something. thanks again!

I hadnt actually made a play controller up to this point… or wasn’t aware of it since it is not referenced as a blueprint in the content browser. In my level blueprint on begin play i just get player controller and plug it into a set view with blend, then create the HUD_Menu (which works but not the first time for some reason). A button on that launches the level on then on begin play of my actor, like you pointed out… I created my other HUD_Widget. When a certain variable is met that actor then loaded the Menu back.

sorry for all the unnecessary comments… Ok, I got things set up using the new player controller and I am comfortable switching pawns now. Things are pretty good except I am still confused on some fundamentals.

Originally I had a camera in the level. In Level Blueprint I set the View with Blend using that Camera at EventBeginPlay.

When game starts… I am viewing from that camera, like I always was. When I switch to Pawn A, it changes to that camera… which is great. When I switch to the other pawn, it changes to that pawns camera… which is way cooler than I thought it would be. So now I want to keep those cameras and switch back to the original… so that after they have selected their pawn… they can toggle cameras between that original camera… or the new ones. Originally I was just going to set Pawn B’s camera back to where the original camera was set.

So it seems obvious I Should just ‘set view’ or ‘set view with blend?’ when the player presses a button. to give them that other camera… the problem is I cannot get a reference to the camera in the Player Controller Blueprint. Or know if that is even what I really want to do.

by the way, no I don’t plan on asking questions forever, lol.

But am super appreciative that you pointed that out about the player controller because that would have been a nightmare to deal with later after setting all the HUD variables.

For the most part I am just testing the basics of everything before I get into it.

I already learned that my setup was way off. So again thanks for everything man, you’re awesome!

This is what I am talking about…

pic011

I feel like I should just get rid of that camera, add one to the player controller… then offset its position to where the old one was.

Ok… I found this.

Switching Cameras

View target with blend is looking for an actor…

and there is a difference between a camera… and a camera actor which is what my other camera was… I just didn’t realize it because I made it using a tutorial weeks ago.

I’m going to stop now because I am way off the original topic and am probably breaking rules or something.

Thanks again mate.

Ok I tried that and this is what I get…

pic012

No problem :slight_smile: