Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

Get Owning Player Pawn returns none on Widget attached to component

Hi Community,

I have a widget that sets player's health bar. I use Get Owning Player Pawn to retrieve my Base Character in which I later use in my bind method to do Health Logic for the UI. Set Character

This works when the widget is set up to a HUD object which is then set as the HUD in the game mode. However when I assign the widget to a WidgetComponent, the Get Owning Player Pawn always returns "none".

HUD Setup working Component Setup not working

Is there something special I need to do in this case? Any help would be much appreciated!

Product Version: UE 4.19
more ▼

asked Mar 26 '18 at 07:43 PM in Blueprint Scripting

avatar image

141 4 10 14

avatar image Nebula Games Inc Mar 28 '18 at 12:10 AM

And yes, even with this method the widget doesn't "calculate" anything with the health it is just told what the health is and can do a basic division to "get percent" or that can even be done in the character BP or when damage is taken in a weapon BP or something. Either way the widget doesn't really do much, it just passively receives the information about actor health and updates a progress bar.

avatar image Impulse21 Mar 28 '18 at 12:19 AM

I see! Thank you so much for taking the time to walk me though that. I will update my logic as needed.

Really appreciate the help and patients :). Not sure how to make these comments as answer.

avatar image Nebula Games Inc Mar 28 '18 at 12:25 AM

I will do it. And thanks, let me know how it goes.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

2 answers: sort voted first

I have had this issue before, I forget exactly what I did but I believe you have to drag the widget component out into the editor and then from that say "get user widget object" I believe is the node and that gets an actual instance of the user widget.

more ▼

answered Mar 27 '18 at 04:54 AM

avatar image

Nebula Games Inc
5.4k 28 9 14

avatar image Impulse21 Mar 27 '18 at 12:47 PM

Thank you for the comment!

Are you referring to dragging the component into Widgets BP script or into the Players BP script that contains the component. I must have forgotten to mention that the above scripts are in the widget BP's "Event Construction". I am trying to keep an instance of the Hero character in the widget BP so I can do look ups on players healths.

avatar image Nebula Games Inc Mar 27 '18 at 08:44 PM

Not exactly sure what the set-up is for component widget in your BP, where everything is located etc BUT if "Hero Character" is the PLAYER character that you are using and you want to modify health variables within then why don't you just call "get player character" or "get player pawn" that will return the instance of the player character (If using a character template BP) or player pawn (If using the pawn template BP) and it should work fine. I wouldn't go for targeting the "user widget" to then get the owning player if the "owning" player is the character you are using, there are much easier ways to get a reference to it as I have mentioned above.

avatar image Impulse21 Mar 27 '18 at 10:53 PM

Well the setup is as follows. There is a WBP_CharacterInfo Widget, that contains a health bar. The widget is used in two places. It is added to a WBP_HUDLayout Widget, which is then added to a HUD blueprint. The second place it is used is on a widget component for enemy characters. I was hoping that within the widget blueprint script I would be able to get "Owning Pawn" check if its of type "BaseCharacter" (Contains the current health information of both Actor) and from there update the health bar as required. I believe calling "Get Player Character" will be an issue since its assuming that this WBP_CharacterInfo is only tied to the player character, but what I want is the WBP_CharacterInfo to work with any BaseCharacter Pawn that it's attached to. My apologies if I am still not understanding something.

avatar image Nebula Games Inc Mar 27 '18 at 11:25 PM

No, not at all. I'm just trying to understand your set up. I've made "parent" enemy blueprints, and used a widget in the components panel that is a health bar and when you attack the enemy the health bar goes down. My issue is not that I couldn't tell you how to do that it's just however I did it doesn't have these issues you're having. And everybody likes their code a certain way so unless you come to me with no starting point I really only tell people to change their code if it is blatantly bad logic. That being said, if the widget is a component of an actor blueprint whenever you have an event that requires updating the health bar of that actor, say on overlap of a player weapon it shouldn't be hard to cast to the enemy overlapped and modify it's component widget. So I'm not understanding why you need to find an owning pawn on construct. It's hard for me to see your logic with that. I think you're making this more complicated than it needs to be unless I'm missing something about your game mechanics?

avatar image Impulse21 Mar 27 '18 at 11:55 PM

Well, the Health logic is all taken care of in the BaseCharacter C++ class. The base character exposes two methods. "Get Health", and "Get Max Health". The idea is that the Widget doesn't need to care how the health is calculated or how it is updated. It just needs to calculate the health percentage every tick so it can update the progress bar to reflect what the health currently is (Image below is my health progress bar bind function).

Widget Health Bar Bind method

So now, what I thought I could do was have the Widget contain a reference to the Base Character that is currently used it. So my approach was on widget construction event, I would get the pawn who owns the widget and if it is of Base Character, we assign it to the variable. I thought "Get Owning Player Pawn" would work for all cases, but it fails when the widget is apart of a widget component. What I think you are trying to say is that the widget should not be setting this reference but its the responsibility of the actor that is using this widget to set this up. Or have the actor pass its health percentage to the widget itself.

avatar image Nebula Games Inc Mar 28 '18 at 12:06 AM

Yea pretty much. I think it is easier to go from the character/pawn/actor that actually has the widget component TO the widget. Since the widget is already a component of that actor why have the widget try and figure out who it belongs to? The actor you placed it on already knows that information. All you need to do is get the specific instance of the widget in the actor BP which if i recall is done with dragging out the widget component into the editor and pull of that pin and search for "get user widget object" that retrieves the specific instance of the widget and from there it is easy to access anything you want within the widget and pass health variables from the actor to the widget.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

I'd suggest an alternative approach. Create a variable of type HeroCharacter in your widget BP, and set it when the widget is constructed and added to viewport. That way you'll always ensure that the value doesn't come to null

more ▼

answered Mar 27 '18 at 08:10 AM

avatar image

21 2 9

avatar image Impulse21 Mar 27 '18 at 12:43 PM

Thank you for the response, however I am not sure I understand. Currently I am trying to set the HeroCharacter variable in my Widget BP. The above scripts are connected to the "Event Constructed" event. If the Widget is instantiated by a widget component, the "Owning Player Pawn" returns none, but if its instantiated by the HUD or directly in code, it works no problem.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question