I’ll try to explain it simply. I’m trying to set a variable in the widget as the same value as a variable in the player bp. TLDR: It doesn’t work. I don’t know why nor how to do this any other way.
Does anyone know how to do this? Thank you all for your attention. An image should be below.
No, and that’s what is even weirder. Because if the value simply did not update, it should still print = 0, but it doesn’t. The whole line simply doesn’t work.
Doing what you suggested resulted in a print, seems like the cast is failing. Any idea of what might be causing this? If it helps, I have another widget BP set up with a cast to Player as well, could that be causing some sort of issue? (even tho I doubt it)
I have managed to fix the issue. While the blueprint up above was just something I was doing for quick testing reasons (I wouldn’t use that setup for later) the issue itself relied on the game mode itself. I had created the game mode and it was set up correctly, but I had forgotten to set the custom game mode in the level settings. It wasn’t using the correct game mode. Thank you for your patience and help on the matter and sorry for wasting your time with such a simple error. I hope you have a great day!
What did it print when you connected the “Get Character Node” to the cast failed print string?
What it prints is what you should be casting to. Is your “Player” Variable a blueprint of the Character type? Is your player pawn even a character blueprint at all?
I noticed this i a widget, and you are using tick to update the player’s HP?
If so, this is generally a bad practice, may be ok for a small simple game, but a bad practice none the less. Another bad practice is binding widget values to variables as they are checked for update every tick. The better method would be to update your entire UI HUD once every tick. What I do is create a Struct with all the variables as a Map. The map is the variable value and a boolean (boolean is true if needs updated). Then, at the appropriate time in my code, I run an update UI HUD, which updates the widgets that need updating. If this i too complicated, a simpler method would be to update the widget when the value changes. So, create a function “Update Health” on your widget, and whenever your character takes damage, call that function with the new health value, that way you can avoid tick.
If you have the Pawn that the widget corresponds to create the widget when needed, you can save it as a variable and you have instant access to taht widget and/or widget object to change the value when needed.
Thank you for telling me that, I managed to fix the issue. While the game mode was correct, the game mode the level was using wasn’t. Thank you for your time! I hope you have a nice day!