x

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"

Casting from an Actor Blueprint to a Widget Blueprint

I honestly can't understand how to cast this and get what I want (see below). I'll try to keep this as basic as possible. Also worth noting that I'm completely new to this stuff.

I have an "Ammo_Box" blueprint and a 'PickedUpBoxes' int variable inside it which is set to 5.

How would I cast the Ammo_Box to my function inside the "FPS_HUD" widget blueprint and get this integer so I can bind it to a text?

For example, the bound text is supposed to say "Amount of picked up boxes: PickedUpBoxes' value"

I'm not sure what to plug in as the Object Wildcard.

I should also note that there are multiple "Ammo_Box" blueprints in the level. Whenever I overlap a box, the 'PickedUpBoxes' value goes down by 1.

alt text alt text

Product Version: UE 4.22
Tags:
pub-5.png (119.5 kB)
more ▼

asked Aug 13 '19 at 11:32 PM in Blueprint Scripting

avatar image

QQWun
8 1 1

avatar image DonBusso 5 days ago

I think you're going about this the wrong way around. Give me 10-15 minutes to put something together for you, then I will try to explain it the best way I can.

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

1 answer: sort voted first

Hello,

Took me a while to put something together but I think this might just work for you. This will require quite some work so be ready to spend some time on this.

First you will need to create a widget blueprint. This will be your HUD, for me it just displays current ammo and plays an animation when ammobox was picked up. Create new variable (integer) and call it QtyPickedUp.

You don't need all this stuff inside the widget and I will not be showing you how to create animation for this as you can find a tutorial on YouTube. It's not hard, really. Okay maybe a little but I believe in you.

When widget is created you cast to your character and set a reference to it. You will need it to access the variables from inside your player character (for us it's ammo)

Third and Fourth images are the bindings for both text fields (x99, ammo(Text Block))

alt text alt text alt text alt text

Once you got your Widget setup (you can just have a text for now to see if it's working) go to your player character (for you could be Third/First Person Character) and create a new integer variable called PlayerAmmo, default (5). Follow the screenshot below. You will need to create a reference variable as it will be used later on to access code inside the widget and set a variable.

alt text

Assuming you have your AmmoBox actor ready with a collision component and a mesh inside. You will need a new variable (integer) that will hold a value of Boxes that can be picked up (for me 5). Select newly created variable and tick Instance Editable. This will allow you to set the variable on the actor from the editor without having to open the actor blueprint.

Follow the scripts from screenshots. I'll do my best to explain and I put some comments around to make it easier.

When your character (for me it's PlayerCharacter) overlaps collision box for the AmmoBox it triggers a script that sets the variable inside the widget that is used in binding function. Now using a newly created reference to player character you can get and set variables inside your character. You can also play animation from here by using a reference to player character that in turn has a reference to HUD which you can now access and execute a function from inside the widget, and set a variable of how many items were picked.

I will admit this isn't the best setup but it should work for you. There are a lot of things that could be improved here but I don't want to make it over complicated, I want you see a working example and maybe come up with something on your own, or modify this to suit your need.

I'm sure you will have some questions and I will do my best to explain.

Remaining screenshots in comment due to limit of 5 screenshots per post.

widgetdesigner.png (205.6 kB)
hudgraph.png (190.2 kB)
bindtext.png (108.3 kB)
bindammo.png (85.4 kB)
createhud.png (148.5 kB)
more ▼

answered Aug 14 '19 at 01:33 AM

avatar image

DonBusso
805 4 5 7

avatar image DonBusso 5 days ago

The animations are quite simple, you just play with position and opacity.

alt text

Gif showing how it works

avatar image QQWun 5 days ago

Thanks! I actually ended up having a very simple solution.

So instead of using the 'PickedUpBoxes' integer in the "Ammo_Box" blueprint, I just made a new one in the "ThirdPersonCharacter" blueprint, since I can just use the GetPlayerCharacter wildcard.

alt text alt text

1.png (135.4 kB)
screenshot-1.png (146.7 kB)
avatar image DonBusso 5 days ago

Good to hear, happy it's all working now. :)

(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