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.