Download

Spawn Emitter on hit using Surface Types

Hi guys, I’m working on a top down shooter game and I’m trying to make a specific emitter (and then, also a specific sound) spawning when a specific surface is hit by the projectile (for example: if I shoot a rock, spawn Emitter1, if I shoot a tree, spawn Emitter2 and so on).
So, I’ve got my physical materials, and I assigned all the necessary Surface Type to them.
Then, I enabled the physics for the projectile (to be precise, I selected the collision sphere of my projectile in his blueprint, and checked “Simulate Physics”), with Collision Preset: block All.
After that, I added on my map a cube, with physics enabled as well (I’m not sure this is necessary) and a Physical material applied (Phys material override: Stone), with collision preset: block all.
Lastly, I built the following node setup in the Projectile Blueprint:

07db2909829466c615a6278291483741e36fb6a4.png

If I shoot the cube, only the first string is printed out (“HIT”), so the hit event actually happens, but there are two problems: the first one is that there are a lot of hit events (the string is printed out several time… how can I have just one hit?) and the second one is that the switch does not work: the following strings are not printed out.
What am I missing? Is this the right way to achieve what I need?

up, I haven’t solvet it yet

Try using a gating method such as “do once” once you’ve successfully filtered out unwanted hits to limit the amount of hit processing.

The other strings are probably not printing because you’re not hitting the right surface type. Hang some specific print strings off the default and carne types to see if they are being hit instead (if default comes up there may be a problem with your setup - perhaps a PM is being over-ridden somewhere) and debug from there.

Uhm… You were actually right.
I cleaned up my Surface Types and rebuilt the entire process: I assigned to a Physical Mat the surface type 1, called “Stone”, then I duplicated a random static mesh that I’ll use for testing; I opened its Static Mesh Editor and assigned the physical material as Simple Collision Physical Material (in the previous test I assigned the physical material as Override, in the physics tab, while the Simple Collision Physical Material slot was empty).
Then I edited the bp as you recommended, like this:

c30c2294f155944b16e24b15e3982ffc90e4db06.png

If I shoot the test mesh, it prints out: “HIT” (just once!) and “Default”, so it hits the default surface type… but I can’t figure out the reason. Now, the Override slot of the test mesh (in the collision tab) is set as None, so it should “read” the Stone surface type…

Uhm… I was wondering if the logics of this blueprint are right… I mean, is that Event Hit referred to the object that is hit by the projectile? Or maybe is referred to the projectile itself, so for every hit event it reads the surface type of the projectile?
I’m really getting confused

EDIT: I tried to add another print string after the HIT one, that for every hit event returns the name of the hit object, like this:

and the result is that the hit object is ALWAYS the landscape! So I’m missing something with the collision presets of the actors, I think… How should I set them?

If you assign a physical material to the proyectile and check it on the switch, maybe you can answer you last question.

…default again, so the hit event is not referred to the projectile.
I’ve set up the collision of projectile as Block All Dynamic, and the test actor as Block All… is that right?

I finally found the real problem! I enabled the physics of my arrow’s collision sphere, so while the mesh was shot correctly, the collision sphere just fell down, in front of the character, right after he shot.
But now… I need the physics enabled in order to generate the hit event. So how can I set up my arrow to achieve a correct shoot? Or maybe, is there another way to “read” the physical material of my target, without using an hit event?

Hi, updating one last time! I finally solved the problem. I made a little research on collisions and discovered that physics enabled is not necessary in order to generate a Hit Event.
What I really needed was to properly set the collisions properties of my arrow’s collision sphere and the test object, so now that’s what I have:

The following is my test actor, the one I was shooting at.
4f3f97cc5aedfca8c0a4963b2fd268055430d068.png
Collision enabled has to be set on “Query and Physics”, but he does not need “Simulation generates hit events” because his work is just to clock the arrow, it does not need to notificate itself about the collision.
Then, he has to Block the object type assigned to the arrow (World Dynamic).

This one instead is my projectile, with the bp set up.
e03161977f34be250229adb5e8fc77f8b9ba06de.png
The collision sphere has to be the component root (can anyone explain me why?), event hit will not trigger otherwise, and its collision properties has to be set like this:
Collision enabled has to be set on “Query and Physics” as well as the test actor, but this time i had to check “Simulation generates hit events” because the projectile has to be notificated if it’s colliding with something, in order to trigger the blueprint.
It also has to Block the object type assigned to the test actor (World Static).
The projectile Mesh instead does not collide.
I also enabled “Use CCD” to have a better collision detection and “Return Material on Move” to make the projectile detect the target’s material after the hit event, in order to return its surface type

The bp is triggered by a OnComponentHit event (I don’t know if it’s better that a normal Event Hit), then it just print out two string: the name of the hit object and its surface type. I’m going now to expand it to make a particle and a sound to spawn, for each surface type in the game.

Thank you I’ll need all this stuff soon

Np, I wrote this down just because someone could maybe find it useful.
I forgot to mention that I also enabled the “Use CCD” and “return material on move” options, under the collision details tab of the collision sphere… going to edit it

Something else I would recommend to add for a long term - “PhysMat” of hit result is not always valid, add IsValid check and some default for cases when it fails. Otherwise SurfaceType well be trying to access null reference.

Oh i didn’t know about that, thaks!
And what if I use instead that “get surface type” function? It takes just the hit as input, not the “PhysMat” pin, so it should bypass that problem… right?

Not completely sure if connecting directly to hit eliminates such problem. You can check with more objects in the scene. Some primitive without physics material. This is more of a precaution anyway.

Well I’ll keep it in mind if I’ll ever meet that problem, thank you again!