Actor's float to HUD

For casting to a character, i understand that it is “Get Player Character”, but what is it for an actor (projectile)?

you need to have a reference to a actor of that class. i like to think of casting as just identifying, so you take in a actor and are asking is this actor like the one im looking for.

theres many ways to go about getting a reference such as traces, overlaps, public variables, and exposed variables. for your case you could have when the projectile is spawned it sets a variable in the widget which will be your reference. of course i dont know the exact details of your setup but thats one way you could do it.

Well, everything i drag out in “object” says “does not inherit from X”. What should i connect to the object pin? I’m trying to connect the “projectile power” float from a Projectile Blueprint.

see the blue output pin of the cast? you want your object in to be that class or a child of that class. in your case your casting to helperTaurusProjectile so the object in needs to be a instance of that object that exists in the level. say you fire your weapon and spawn a projectile, that projectile is what you need a reference to.

ok as a little example lets say your widget is created in the player character, and your spawning your projectile there as well. in this case you could create a variable in the widget named ProjectileRef of type actor and connect it to the cast. then in the player you go to where you spawn projectile and you take the output return value (which is a reference to the spawned actor) and you set the variable in the widget to this actor. Maybe if i have time later ill add pictures.

If you can explain the context a bit, such as where the widgets created and what its displaying, basically the overview of whats happening then i can give you a more specific answer.

I’d like to know what to connect to the “object” pin

simply put you need a actor reference. that is a reference to a specific actor that exists in your level. the reference is like telling the widget which actor’s information you want to be accessing and showing in the widget.

below is an example like i described above.

you see in the player character i create the widget then save a reference to the widget in the variable widgetRef which is of type w_ProjectilePowerDisplay. with this reference i use a specific class so we can access its information and variables directly without casting.

next i have a input event which spawns the projectile(testProjectile) into the level. we then take our reference to the widget and in turn the variable ProjectileRef stored within it and we set the value.

the next picture shows the variables attributes in the widget. as you can see its type is set to actor so this variable can store a reference to any type of actor. since all the variable knows is that the item is a actor then we will require a way to identify the specific class of that actor so we use a cast. the object in for the cast needs to be either the class that your testing for (in this case TestProjectile) or one that inherits from that class (a child of TestProjectile) to succeed.

casting is based on inheritance which is an important topic when making games and programs. its very similar to taxonomic ranks which we all learned about in biology class (Taxonomic rank - Wikipedia). all classes inherit the qualities of the parent, so characters can do all things that a pawn can do but a pawn cant do everything a character can, character inherits from pawn which inherits from actor etc etc.

I don’t really know how to respond to this!

I’d like to know what to connect to the “object” pin.

It’s not that complicated, just a widget in Content and a projectile blueprint that has a “projectile power” float…

Thanks 4 your effort but this sounds super impractical and complicated. Progress bar there, widget for the projectile, values from child actors, would just make a huge mess in my Blueprints. I think I’ll wait out or experiment for a more simplistic solution. :slight_smile:

its actually a quite simple and basic thing.

you should really elaborate on what your seeking to accomplish otherwise your really not going to get answers specific to your project. also i don’t think you understood much of what i was saying here. you mention widget for projectile and child actors in your last comment, i set it up as one widget and what it displays changes, and as for the child actor part that was added in as extra information to teach you about casting. many times people will just say do X and put xyz in this order to do the thing, instead i gave a general solution and included information for you to learn how the system works so that if you run into the issue again you will know how to solve it.

really though the basic solution has been stated many times, you need a reference to a actor to plug into the cast. if you want a specific answer on how to get that reference then tell us whats going on in your game. all we know from what you’ve said is you have a projectile and you want to get a value from it to display in a widget. with that amount of info you can only expect the most basic solution stated above.

oh and if your looking for a node like the “get player character” which will be your one node solution to the problem, it doesn’t exist.

heres a link that may be of some help to you. the below link is to the unreal engine training stream on blueprint communication. I would say that between time 10-20 is most relevant to you currently as it discusses direct blueprint communication, casting, and references, but i would suggest anyone new to blueprint to watch the whole thing.

. also i don’t think you understood much of what i was saying here.

You got it! I cannot visualize the info you’re providing to me. Started with UE4 2 months ago. May I give you my drumsticks and you’ll play a song of my choice from beginning to end? :slight_smile: let’s start with this one.

It’s is too much info for a beginner like me, but I will get further into your solution once I can comprehend this information better. Thanks a lot for hammering it down. It’s sad that the engine doesn’t have a simple pin to drag out.