I’m toying with the fly template and I tryed to figure out how could I show my flying objects speed and mass on screen while I play. I did get the numbers show on the screen, but both values stay 0.0 whole time.
I’m trying to get speed working first and I get this error
Error Accessed None ‘Flyer’ from node ReturnNode in blueprint DebugHUD
instead of setting flyer on EventConstruct, try EventBeginPlay.
the construction script is run in the editor, whenever you update an actor. you wont have a player controller while in the editor because its spawned during gameplay.
also, after the speed node and before the ReturnNode, you should add an IsValid node to check if the Flyer variable is null. that way, when the pawn gets destroyed, it won’t crash from trying to get data out of a non existent pawn.
and also, you should not add the return value to viewport, you should add WidgetVar to viewport, because that reference allows you to remove it from viewport.
you don’t need event begin play in the widget, you can use the event in the HUD.
in the HUD:
after creating the widget, and setting widgetVar, you can set widgetVar::Flyer, then add widgetVar to viewport.
inside the widget, you don’t have to do anything to set up its references, you can handle all of that from the HUD, because the HUD has better access to the pawn, playerstate, widgets it spawns, etc…
i use the Hud as a central place to manage the references to data that needs to be displayed. in the Hud i always check if the references i need are valid, and if they are not, i continually attempt to update those references every frame until they are valid.
pfff. Thanks for all the help. You guys teached a lot. But apparently it was all about variable types.
I connected float to a draw text node, but what i had to do was create a string variable in my flyingpawn BP and connect my flyspeed float to it. And then get that string variable in my HUD BP.
Thank you again for all the help. Trying to explane your problem when you don’t really understand whole platform, can be a frustarting thing to do