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"

How to get variables from Tagged Actor

So basically in my game, there is going to be a lot of different monsters, and a lot of different bullet projectiles coming at the player. I want to check if the actor that hit the player has the projectile tag, and then pull the variable of BulletDamage from that actor to replace where the Damage variable is at the moment. How would I go about doing that as I do not want to cast to every single type of bullet in the game.alt text

Product Version: UE 4.15
more ▼

asked Apr 25 '17 at 03:02 AM in Blueprint Scripting

avatar image

Kaji Ikaraseru
3 1 2 4

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

1 answer: sort voted first

You don't need to cast to every bullet type individually. Instead, make a parent blueprint with bullet type, damage, mesh, etc.. variables, then make as many child blueprints as you'd like.

Doing that, you can just cast to the parent and still access the child data. You also wouldn't even need to check a tag, since if the actor is NOT a child of the bullet parent, the cast will fail. It's its own check :)

more ▼

answered Apr 25 '17 at 03:47 AM

avatar image

1.5k 65 132 103

avatar image samnater Apr 25 '17 at 04:24 PM

This is exactly how I would go about this. Parent classes with child classes are the way to go in blueprints.

avatar image Kaji Ikaraseru Apr 26 '17 at 12:39 AM

So then if I took the Bullet Damage out of the cast to the parent, I could still change the Bullet damage in all the child actors and it would access that damage? To do that would I need to make a variable in each child with the exact same name, or do the variables get inherited by the children?

Sorry, I am quite new to UE4 and I never really used parents and children.

avatar image talislincoln Apr 26 '17 at 01:09 AM

Yes, that's not really a UE4 feature. This is a programming thing called inheritance. Like it was already mentioned before. All the variables that should be in all the different classes should be added to the "parent" class, and so, all the children would have the same property. Let's say you want to create 3 different type of bullets, but they all would have a mesh, a particle effect, damage and velocity(?)... You name it. So then, you would create a base class, lets say BP_BaseBullet, with all these properties. Then you can right click that blueprint and create a child class from that and call it BP_TankBullet that would have an iron ball as mesh, damage of 30 and smoke as effect. That you would go back and right click BP_BaseBullet to create a new child and call it BP_RifleBullet that would have a small iron ball, damage of 5 and a different smoke as effect... And then so on.. So basically, each child can have its all properties different from the parent and also from it's siblings.

At the same time, all the children are also a "BP_BaseBullet" so you could cast any of the bullets to BP_BaseBullet and get the damage property from it.

This idea would also be applied to functions. You could create a function on the parent class, and override in the children. So when you cast to the parent class, it would call the children function.. just make sure that you override the function by clicking this button and selecting the function that you created: alt text

This whole concept can be a bit confusing, but that's a very useful concept to understand if you beginning on game programming.

ps: Whenever you do that with the variables, make sure you select the option to visualize the inherited variable, otherwise you wouldn't see the damage. Like so: alt text

f.png (5.1 kB)
ss.png (19.0 kB)
avatar image Kaji Ikaraseru Apr 26 '17 at 01:34 AM

Oh my god, I tried this way before, however I was wondering why I did not inherit any variables. Thank you so much everyone, you all helped so much.

(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