So I am new to Unreal Engine overall and started following Smartpoly’s beginner blueprint tutorial. When he created a blueprint for a door or a hat pickup I thought that I got the gist of get player controller and casting to third person. But then when creating a damage box and health system, he randomly added a get owning player pawn for the Widget BP health bar. But then used get player controller while in BP_thirdpersoncharacter. I am completely lost. I mean also when I tried changing the “get owning player pawn” to other objects it seemed to work exactly the same. How? Why? Someone explain please
Some nodes in Unreal Engine’s blueprints have an object pin. Those nodes need an object reference to work, even if it’s self. For example, imagine the “Set Actor Location” node. What that node does, is setting the location of an actor, right? So it needs an actor to modify. Some other nodes may not modify the actor but still need to use it, like in your example. The “Cast To” node needs to access the parent class of the blueprint you’re trying to cast from. You can understand it better if you already know C++, it’s just like how you access the functions, structs, enums defined in a class. You can’t just type in “func();” right? You should instead write “ParentClass.func();” and a similar thing happens in the second image you sent. Hope this clears everything up
Essentially, the player pawn is supposed to be controlled by a player controller (see Gameplay Framework in Unreal engine | Unreal Engine 5.4 Documentation | Epic Developer Community). Think of an RTS game where you can switch between characters but still be able to move them around and such. That’s because the game’s input and UI is handled by a player controller.
So when the widget is spawned, it uses Owning Player to store a reference to the player controller (this isn’t technically necessary in a singleplayer game; you can really just use Get Player Controller in the widget). Then, the widget asks the player controller what pawn it is controlling and casts that to your ThirdPersonCharacter class.
But in the end, all that is largely unnecessary in most cases. You’re supposed to handle input and such in the controller and send that data to the pawn, but most people just put it all in the pawn in singleplayer games. So in this case, you can simply use GetPlayerCharacter in your widget and cast that to your ThirdPersonCharacter class.
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.