How do you change a HUD image based on a BP variable

I basically have 2 images for my HUD one showing a key picked up and the same image with a cross over it for key not picked up. In my HUD BP I have created a BOOL for key grabbed and switch the images based on it.
This works if I set the value of the BOOL manually the HUD image swaps as expected

Then in the BP for the KEY object itself I have created a reference to the HUD and set the HUD variable once the key has been grabbed

This unfortunately doesn’t work and I get the access none error as the object is not assigned???
Since I cant select the key actor in the scene and right click and create a reference to it in the HUD BP how do you go about setting this up.
You can get reference of scene actors from other BPs but not the HUD BP it seems …very confusing.

Hi,

Have you set the keygrabbed Boolean variable as public. In MyBlueprint > Variables > next to the variable name there is an eye symbol > set it to open (public). This means that this variable value can now be changed by other blueprints (otherwise it is protected so it can only be changed inside its own blueprint).

Otherwise, have you checked that the reference to your HUD is valid (put breakpoint on the node and check it has a valid value at run-time)?

Thanks for your response…
Yes keygrabbed was public… No the REF object was not getting populated as indicated by the “no access” runtime error.
I found in the key actors BP I could get a reference to the HUD keygrabbed variable like this…

Don’t know if this is recommended or not but for now it works. If you have any input on this causing issues farther down the track I would appreciate hearing them.

Hud no key…

59820-hud+nokey.jpeg

Hud with key…

59821-hud+with+key.jpeg

Looks a pretty solid way to do it. You might also want to set a variable in the player controller with the Id of the key that was picked up (if you had lots of keys) using the same method you’ve already used (Get Player Controller > Get/Set Variable/Call function).

If you wanted to make it multi-player in future with each player having their own HUD, you may want to get the player controller reference in a different way. E.g. if your key grab code is triggered by an overlap event from a players controlled pawn/character or a projectile they instigated:

In your Default Character BP: Create a variable of type {MyPlayerController} and call it MyPlyrCtrlRef (for example) and set it as public (or make a function that can set it).

In your Player Controller BP: At the “Event Begin Play” event, call “Get Controlled Pawn” and cast its output to your default character type, from the cast output set the variable you made above (MyPlyrCtrlRef) by passing it the player controllers “Self Reference” node.

Now, when your controlled pawn causes an overlap event (or a projectile it has instigated), you can cast the “Overlap Event” > “Other Actor” output pin to your default character type and from the cast output get the MyPlyrCtrlRef variable you created and set above (a reference to your player controller), which you can now use to connect to the “Get HUD” node in your image above.

In the mean time, might be easier to just use get player controller 0 :wink:

Game looks cool :wink:

Thanks for your help.
Each piece of functionality I try to add opens its own can of worms.
I’m having huge issues aligning the picked up objects to the skel mesh socket.
In the skel mesh editor where you are supposed to be able to align them my attached meshes are enormous???
How are you expected to adjust the position!

Lol, It can be like that :). Sometimes the way UE4 does things seems a bit strange at first. But there’s always (usually) a way to do it once you find it…

Not sure. A few issues I’ve had with importing and attaching items. 1) When you export the mesh from your 3D modeller (3Ds Max?) make sure the mesh is placed at the 0,0,0 origin of its scene when exported (as the mesh when imported to UE4 will keep that same distance from origin when generating its gizmo/pivot/attach point)(can also be helpful to place the handle of any object that’s going to be held at the origin, then you can snap it straight to the socket in UE4). 2) I guess you could either rescale the mesh in the 3D modeller; or open the static mesh editor for the asset you want to attach, then in Details > Transform > Import uniform Scale, set the scale as required and reimport; or you can create an actor blueprint for the equipment you want to attach, add a static mesh component and add and resize your mesh in there (see below for quick node diagram to spawn and attach some equipment to a character - note: rescaling the equipment mesh, no collision set otherwise the attached equipment will continuously collide with the character making movement jittery, mesh is the character skeletal mesh component)…

Ok …aligning the mesh in the modelling package (Blender) has fixed the orientation and thanks to your (placement of the handle around the origin tip) fixed the position. The mesh is scaled 1x in Blender so I have no Idea where the huge scale issue is coming from in the skel mesh editor in UE4. It doesn’t really matter at this stage as in game the mesh is scaled correctly.

Your BP was a real eye opener. I was destroying the component “Box collision” I had added to the BP to stop the jittery rendering once the gun was picked up. I see now you just use the “set collision” function. I thankfully won’t need to adjust the scale of picked up items I will just ignore their appearance in the skel mesh editor (for now). I should just be marking all of your answers as correct but with your wealth of knowledge this may be the quickest way to create a first game in UE4 ever. I’m going to attempt to make him shoot something from this gun

60156-gunalignedcorrectly.jpg

.

Lol, love the ted … :))

Well… I thought the shooting would be a breeze . Spawn a projectile BP from the location/rotation of the rayrifleBP.
I created a simple projectile .

60301-rayred.jpg

In the animBP for the char there is a shooting anim with a BOOL “isshooting”…In the state machine once isshooting is set it animates with the shooting anim this all tests out by manually setting the “isshooting” var in the previewer.
I have created a fire function in the guns BP that just spawns the bullet BP at the guns current location rotation.

Then in the input action shoot (left mouse click) inside the gun BP I call the fire function only if the gunpicked up var is true.

60289-input+action.jpg

I tagged a print on the end of the spawn actor in the fire function.
it never seems to fire.
I also can’t figure out how to acces the “isshooting” var in the anim BP to play the shooting anim.
I enabled input on the rifleBP at event beginPlay.
I am starting to think BPs logic is beyond me.

I managed to get the bullet to spawn correctly using input action shoot in the charcontrollerBP…

Now when I try and update the animation to the shoot animation I keep getting “access none” on the Object var . I thought you could create an object reference to another BP so you have access to its variables…
when I do this in the animBP event graph

I get the “access none” error…how are you supposed to access vars between blueprints?? I thought I read in BP comms docs this was how you do it.
The methods seem different depending which BP your in and which you want access to. In the level BP you can right click and create a reference to the selected BP. In others you cant, and if your trying to access something not in the level you do it via the class ??? How on earth do you simply set a variable in one Blueprint from another?

Hi, I had some difficulties getting all of the references to the engine generated class instances at the beginning. Did you set the object reference to the character? Try this:

In your Animation Bp, use the “Try Get Pawn Owner” node and cast it to your character type (and save it to an object reference variable of that same type in you Animation Bp) you should now be able to use that reference to get access to the variables in your character instance (note: the animation blueprint is spawned (instanced) before its associated character, so the first few runs through “Event Blueprint Update Animation” will fail the cast until the character has been spawned):

An alternate way to do this is to create an initialisation function in your animation blueprint that will save a passed reference to you character, then in your characters “Event Begin Play” call that function (will have to use “Get Anim Instance” to get a reference to the animation Bp that was instanced for your character (defined in the character component > mesh > details> animation)) and pass it a self reference:
(Image Below: Character Event Graph)

Note: If you do this, you won’t have to do the cast and set in the top image, which will run every time the event triggers. You could also set a Boolean in the image below “PostInit” to true, then put a branch node after the update animation event that will only run the rest of the event code if PostInit is true (Image Below: Anim Bp function)

60549-bpinit3.png

For future reference, the order in which engine created objects are spawned (instantiated):

Player Controller is instantiated and runs “Event Begin Play” before the Level Blueprint, Game mode, and Player State have been constructed (i.e. Player Controller will be created and run Event Begin Play before the Game Mode and Level Blueprint Construction scripts are run).

Also in “Ai Controller” blueprint, the “Get Controller Pawn” node which returns the character for whom this Ai has been instanced returns none from Event Begin Play". It only returns the valid character after Event Tick (again seems the Ai is instanced before the character). It seems this is also true for the Animation blueprint, when using “Try Get Pawn Owner” from the “Event Blueprint Update Animation” event, this will fail for the first few runs through the event until the character has been instanced.

This may seem back to front (trying to start the engine before it’s been put in the car). I would have thought ideally you would instance the level first, then the Player Controller, then the Players State, then the players character, then the characters Ai and Animation blueprints, but there’s probably a reason…
(Image Below: character AiController Event Graph)

Yep, as you say, I think there’s a lot of different specific nodes for getting references to the different game objects (e.g. get player controller, get game instance, get game mode, map actors etc) and it took me a while to work out how to get data from one place to another. It’s only in the level blueprint you can get a reference node to an actor selected on the map (as that’s the only blueprint that can be sure that that object exists).

For example, I don’t think you can get a reference to the level blueprint from the player and game blueprints (not sure if there’s even an object reference type for a level). Not sure if its the best way, but in my Level Blueprint I got a reference to my game instance using “Get Game Instance” (I guess you could use Get Player Controller directly instead), then set variables I created in game instance to store any data I wanted available my other blueprints, then in the other blueprints did the same to get the data back out of my game instance.

Thanks for the thorough insight.
Having an understanding of which order things are created and how they weave together makes the logic much easier to follow. The uses of the different methods depending on when and which BP type (level,anim,game mode, hud) your in will still cause me future stumbling blocks but I will be able to come back here and re read this post . I see now the ref object was not being set to anything at the time I was trying to access its variables…

I got the "try and get pawn owner " “cast to char tedchar” then set a "ref object " working instantly after reading this post and it made sense.
I guess I should set “location and rotation” from that ref object also not the way I’m doing it in the snip below…

Since I can’t shoot until I pick up the gun via logic elsewhere in BPs and Im not starting play right next to the gun I am getting away with it.
I will tinker further.
But for now …ted shoots!!!

60699-he+shoots.jpg

After a little reading and watching the Tutorials I also managed to get him to continue running while shooting via the "layered blend per bone " node.
This engine thing is quite amazing. The more I do the more sense it seems to make. Mostly from being set straight by you’re posts.
Thanks again.

What to do next?? I really should of had a design before I started this but “collectable Blocks” and evil Doll enemies come to mind right now while I’m typing.