Widget cast failing

Any ideas why my cast is failing…? Trying to get my HP bar
Followed a tutorial, it works for my enemy but not my player.
Basically: my HPBar widget is on my character, and i’m setting and initializing it in my controller, bc it has the HP variables. Should i just store the HP in my player character and use my character and my controller more tightly together? (storing a ref of each other on Init and going from there?)
Here are the BPs:
1- my character (player)
2- my init health bar function, in my character controller
Errors:


PIE: Error: Blueprint Runtime Error: "Accessed None trying to read property Health Widget Ref". Node:  Set MaxHealth Graph:  InitHealthBar Function:  Init Health Bar Blueprint:  BattlePlayer
LogScript: Warning: Attempted to assign to None
    BattlePlayer_C /Game/Battle/UEDPIE_0_BattleLevel.BattleLevel:PersistentLevel.BattlePlayer_C_0
    Function /Game/Battle/player/BattlePlayer.BattlePlayer_C:InitHealthBar:0115
PIE: Error: Blueprint Runtime Error: "Attempted to assign to None". Node:  Set MaxHealth Graph:  InitHealthBar Function:  Init Health Bar Blueprint:  BattlePlayer

“Attempted to assign to None” is logical, since the cast is failed, the ref isn’t set. I’ve got my logged string on cast failed displaying too btw so we’re sure it’s this

The reason is, that a 3D Widget component is actually not a Widget.
So… your Reference of “Health Widget Ref” is just a Reference to the Widget Component… but not the Widget inside.
So your Event Calls try to invoke Events, that are existing in your Widget… but not the Component.

Try this:


*UIColor is just a Dummy… you need to cast to your own one…

1 Like


I did this : nothing changes :confused:

OK… Another try

1st:
Can you print out on succeeded cast, too?
Perhaps it is triggered … But…

2nd:
Cause sometimes it happens, that a cast loses his ref after using it…
Try to add a return of your HPBar in the Init function and use that to set a value.

1 Like

Character
Controller
like so?
You can see the “HEKP” log in the error below, so we know the cast is failed BUT
Interesting fact is that it’s supposed to be getting the display name of the widget, and i get “[CharacterBattle_C_0]”… Weird, isn’t it?
see my error: LogBlueprintUserMessages: [CharacterBattle_C_0] HEKP LogScript: Warning: Accessed None trying to read property CallFunc_InitHPBar_HPRef BattlePlayer_C /Game/Battle/UEDPIE_0_BattleLevel.BattleLevel:PersistentLevel.BattlePlayer_C_0 Function /Game/Battle/player/BattlePlayer.BattlePlayer_C:InitHealthBar:011E PIE: Error: Blueprint Runtime Error: "Accessed None trying to read property CallFunc_InitHPBar_HPRef". Node: Set MaxHealth Graph: InitHealthBar Function: Init Health Bar Blueprint: BattlePlayer LogScript: Warning: Attempted to assign to None BattlePlayer_C /Game/Battle/UEDPIE_0_BattleLevel.BattleLevel:PersistentLevel.BattlePlayer_C_0 Function /Game/Battle/player/BattlePlayer.BattlePlayer_C:InitHealthBar:0133 PIE: Error: Blueprint Runtime Error: "Attempted to assign to None". Node: Set MaxHealth Graph: InitHealthBar Function: Init Health Bar Blueprint: BattlePlayer

Thats interesting, indeed :thinking:

Can you show us, where you call the Controller function?

image
lmao

okay…
So… Multiple Possibilities:

  1. You drag&dropped your character Intro the scene via Editor viewport…
    Means… Your PlayerController has no info about this character, but gehts the name from the cast ref
    Means… You need to possess this character via PlayerController first.

  2. (I think this is what you have there) You didn’t spawned the character by yourself, but via GameMode setting (Default Pawn). In this solution, you better call the InitHealthBar from the OnPossess Event… cause the pawn is not existing (PlayerController is spawned before Pawn).

  3. You deleted the default pawn of the GameMode and spawned the actor via LevelBP or any other BP that exists in the Level. Then you need to possess it via PlayerController first.

  4. You try to get the PlayerCharacter… But… Perhaps you need to Get the Player Pawn.

1 Like

on possesss??? Dayummm checking this, brb
Update: nothing:
image
Update²: my bad! i linked everthing and it works like a charm now :slight_smile:

1 Like

Okay update again: it doesn’t work :woozy_face:


same errors
@BDC_Patrick (i was scared you wouldn’t see the message cuz you’d think it was over)

OK… Then… Question:

Did you set your Character in the GameModes default pawn?

Or…
Did you drag it over from the content browser into the level?

Or…
Did you spawn the Character Actor by another BP?

i did the first one!
image
And the widget is latched onto the one we want
image
( @Everynone )

Not sure if it was mentioned above, but are we sure the comp is holding onto a widget of the correct class?

image

Ignore me if it does.

:cool:, just checking. You never know.

Did you try delaying Init Health Bar by 1s or so just to test it out? #grasping_at_straws

i’ve been having this nonsense issue for two weeks now, and it’s driving me nuts, especially when i compare everything side by side, and the difference with the enemy and the player when i put a breakpoint on the cast is :



Well, we see the GetUserWidgetObject is the thing f*****g it up.
And when i compare the components side by side in a hope i forgot to link one, there’s absolutely nothing

Having the same problem here