I’ve made a Blueprint based on Pawn, and have made a basic ammo system for it. When the left mousebutton is pressed, it will subtract the ammo pool by 1 every 80ms*(Currently using Timeline for this, is there a more effiecent method?)*. The new ammo is then stored in a variable.
I want to get this value onto the HUD via UMG, is this possible? This is what it currently looks like;
Also, is there a way to turn this into some event? For example, whenever the variable is subtracted by 1 and updated it will trigger a custom event, IE “onCIWSWeaponFire”. And can I then use this event in other Blueprints…?
The Umg docs contained some examples of using variables to change material parameters. have you looked at that yet?
Also I would not recommend calling the function based on a timeline.
It should be based on the event ReduceAmmo etc itself.
Thanks for the reply, I’m not using any material to display the text - so I am not entirely sure as to what you’re talkinga bout. I’ll see if I can find the documentation for UMG and see if there’s anything useful.
Also, this is not based on ShooterGame or anything - I don’t have any event called ReduceAmmo.
Wouldn’t it somehow be possible to make a function which fetches the variable, and which I can later call within UMG? I really can’t figure out any way to do this using UMG. Any help would be greatly appreciated, starting to lose hair :rolleyes:
If you are just looking to show a number it’s not too hard to do. You just drop the text box into UMG’s designer and then next to the text entry field click the Bind link. This will create a function that you can use to get that variable. Depending on where you have it you need to cast or use an interface to get to it and hook it up to the output of the function UMG created for you.
Or you can you can just create a text variable in the UMG blueprint, bind the text block to it and cast to it. No function needed.
Thanks for the answers, I’ve made a variable within the UMG Widget I made - but I can’t find a way to transmit data to that variable. I’m very new at this, so it’s very much possible that I’m overlooking something… I have absolutely no clue how to work with Blueprint Interfaces.
Looking for a similar answer. I’m thinking probably a good way to do this is call the UMG element within the actual Actor Blueprint and see if that works. I’ve been trying to do that but I can’t seem to get the UMG element to render using this method. I’ll look for a solution in the same fashion.
Basically you want to go ahead and reference your blueprint within the UMG Function. You can do this quite easily by doing the following.
- Create a new Variable in your Blueprint.
- Set the Variable type as Object and reference your Object as your Blueprint. These are normally the Blueprint Name followed by an “_c” so if your Blueprint with the data is called MyCharacter, the Object you’re looking for is MyCharacter_C.
- Get that variable and add it to the Blueprint. You can use Ctrl+Drag to do this.
- When you draw out from the node, just type in the name of the variable you’re looking for. Then go ahead and connect that to the text box you’re trying to link the number too. You’re good to go.
If you want to figure out how to bind your widget to a function, you can look at my FPS Counter tutorial @ https://forums.unrealengine.com/showthread.php?29923-Simple-FPS-Counter
Hope that helps.
Here is a link to a sample project that I pasted in the UMG Doc thread to try and get support for another issue but you can use it as it shows how I have gotten communication to work.
Also I just whipped up a quick video see if it helps. It is not complete but shows the basics of how I create a widget, keep a reference to it, get that reference from somewhere else, and set a value of a text block. I kept in my mistakes and it has no audio but hey i whipped it up in a couple minutes and it might help =)
Thanks a lot MathewW, that was exactly what I needed!