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.
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.
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
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.
(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).
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.
You try to get the PlayerCharacter… But… Perhaps you need to Get the Player Pawn.
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