I created a Character in my level. This Character has a blueprint associated and in this blueprint I created values (name, age,…).
I want to create a widget that, when opened by pressing a key, will display the information (name, age,…) but in my Widget Blueprint I can’t directly access the variables.
All the variables are public and I also tried to create a Getter function in the Character blueprint but I still can’t access it from the widget blueprint.
Is there a way to transfer, cast the values to the Widget ?
Yeah, normally, you just do “GetPlayerCharacter 0”. Cast that to your CharacterBlueprint Class and get the Variables.
So what exactly did you try (screenshots maybe?) by now and what is exactly failing?
Thank you for your reply !
Here I have my function defined in my Character Blueprint:
When the player presses the key L, the Widget is opened:
In the widget, I want to display all the information about the character. I began by adding a Progression bar to display the life:
So how can I use the function created in the first screenshot inside the widget blueprint (Last Screenshot) ?
EDIT: Although wait, you should better do the following:
Create a Variable of Type “Character_Blueprint” (Reference) in your Widget.
Select it and chose “Editable” and “Expose on Spawn”. Hit Compile.
Now you should see an input pin with that Variable in the “Create Widget” node (second Screenshot).
Pass “self” to this, so you pass the object of that Character_Blueprint class to it.
Then you can use the Variable in your “GetPercent_0” function to call the function.
Make sure you use “IsValid” on your References so you don’t get Accessed None Errors when they are
empty! You can duplicated “ReturnNodes”'s to have one for each possible exec way.
Thanks a lot, I’m beginning to understand and it’s beginning to work.
Therefore I still have a problem when I try to pass the character to the widget:
Thank you !
EDIT: A better screenshot
Oh, i though the L key is in the PlayerCharacter. SORRY.
When hitting L, use "GetPlayerCharacter 0". Then, drag out the return value of that new node and search for “Cast to Character_Blueprint”.
The connect the input exec with the L Pressed exec and the top most output exec with the “Create Character Information Widget Widget” Node.
And the “As…” Pin of the cast node with the Character 1 Input of the “Create Character Information Widget Widget” Node.
Looks like you have your question answered. I wouldn’t complete pass everything over in one function though. I would create functions in your widget to pass though specific/relevant variables to your widget. Then call those functions within your level or character blueprint.
I would use get owning pawn or something in case your game gets multiplayer …