How can I check what a projectile hit?

How can I check what my projectile hit in my scene?

I basically want this, I know it is incorrect, but it shows basically what I want:

https://gyazo.com/ba315b0a36d14f1457fa3225e58ddd40

I just can’t figure out how to do this.

That still doesn’t do what I want, I want all the code to be executed in the BP itself as I displayed in the screenshot above, adding interaction to it still doesn’t let me check what it hit.

I don’t use trace lines btw, I use event hit.

HI!

This is basic setup. For example I used First Person Projectail from FP template.

For collision component I added OnComponentHit event and use Hit output to get the name of object which was hitted.

Add boolean variable Fire! for registered only first hit. Default Fire! is False.

Add Actor variable Name type and set the object with needed name.

In FirstPersonCharacter blueprint in Spawn projectile section, set the variable Fire! in True.

You will get a message on screen, when your projectile hit object with name FirstPersonCube_Rounded2. All other objects in scene will be ignored

Is there no way to detect all objects in a scene? Because when it hits a NPC of which I plan to have multiple it needs to do damage(already figured that out), when it hits a destructible mesh it needs to do XX and when it hits a static mesh it needs to do XXXX(X being a placeholder for the action), I don’t want it to detect one object, I want it to automatically detect the object.

You can use Blueprint Interface. And when projectile hit on object, object will print own name.

Create Blueprint Interface.

Open all base blueprints and add this interface to them. When You add interface, you can create Events named like function in BP Interface.

Open projectile BP and add function from BP Interface.

And after hit, all objects will be return its name in scene.

But then I still need to manually check what each name is, is there no way to find out what the object is automatically?

Not the name, the object type.

That’s exactly what Interfaces are for. You declare one function ReactToHit (or whatever) in the interface. Then for each of the classes implementing the interface, this function could do something different. It’s really extremely flexible.

yes it does. adding an interface does allow you to check what you hit, and it does exactly what you are asking for, you just need a return value that identifies the object. an interface function can not only message an unknown object without casting, it can ask that object to send back some identifying information very efficiently.

you really should use an interface for this functionality.
your current solution is very high maintenance and very low performance. in order to solve it your way, for every new object type in your game that you want your projectile to interact with, you would have to add another cast node to your projectile. if you had 100 things to check, and your projectile hit something that doesn’t even interact with the projectile, it would still have to do 100 cast attempts just to realize that the thing it hit isn’t important.

cast nodes are expensive, and doing a lot of casting in a row like that could cause a huge performance hit. without casting to an object, you cannot call functions on that object and you cannot pull properties from the object, so the only way to know if you can cast to an object, is to attempt to cast to it.

there is a better solution, and i posted it 3 days ago. interface functions allow you to talk to actors, without knowing what the actor is. they also allow you to return variables to the projectile that called the function, so the projectile can identify what it hit without casting.

an interface function does exactly what you are asking for, you just have to use a return value to identify the object that was hit. as a bonus, the object that was hit also has a chance to perform some logic, in case it wants to fall apart or catch on fire.

1 Like

If all you want is the object type, you can use the Get Class node. If you want, you can then use the result to, for example, compare against a specific object class.

Can you tell me how I should do this? I am fairly new to this so I have no clue how to, I would appreciate it.

follow the video i posted above. at 5:30, you can see him setting a category. right below that is inputs and outputs. click New for the outputs, and set the variable type to integer, and name it ID. then at 5:50, you can see him going to class settings and using Add to add an interface from the dropdown list. after you add your interface to each object, you can open the function, set the integer on the output return pin to something unique. then when you call the interface function OnHit, drag off of the “Other” pin, and call the interface function on it, get the integer from the function, then you can check if its equal to another integer, or check if its above a certain amount, or you can switch on int. or instead of returning an Int, you can return a name, and switch on name or compare names.

also, make sure the collision primitive on your projectile has its collision property “SimulationGeneratesHitEvents” checked, or you wont get any hit events.