Download

Using Event Hit to Spawn Actors

Hi there, I see to be running into some trouble with using the Event Hit component to spawn and actor at the location of collision with a projectile and another actor. I think the problem is coming from the collision not triggering with my projectile but when I run the simulation on the blueprint, I cannot see anything occurring at all. When the projectile does reach the edge of my level however, the actor does spawn. I am new to unreal 4 and blueprinting in general, so any tips or corrections on my blueprint would be greatly appreciated! a2858ecbbe231878eb91e5c966c11c79e1e45bf9.png

Hey there and welcome to the forum,

so first of all, instead of doing the “GetClass” thing, you can simply FIRST check if the “Other” Actor “IsValid” (the Node is called exactly like that. Use the one with 2 execs, not the bool one)
and then cast the “Other” Actor to the class you wanted to test. So in your thing it would be casting to “FirstPersonCharacter”. If that “Other” actor is not of the same type or a child, the cast
will just fail. So if it succeeds, you know it’s the correct class, if it fails, the Actor has a different class.

Then you should be careful with blindly calling “GetAllActorsOfClass” and directly using “Get 0” on the Array. There could be a situation where the Array is empty (so “Get 0” will lead to an
“Accessed None” error) or the Actor you get from that is not valid at the point you call “Destroy” on it.

So make sure to check if the length of the Array is “> 0” and make the “IsValid” call on the ReturnValue of the “Get 0” to make sure you don’t call it on something that’s not existing anymore.

The Spawning should be ok. It would be important to know if this is a multiplayer game or not. So that you don’t do mistakes with Replication :stuck_out_tongue:

I guess you are checking the class of the “Other” Actor to make sure it’s not colliding with the Player. Instead of doing this, you should think about creating new Collision Types in the
Project Settings and giving the Projectile his own Type. Then you you can set the “Pawn”, or what ever the Type of the Player is, to be ignored on the Projectile Collision Settings
and the “Projectile” to be ignored on the Players Collision Settings.

You also need to make sure that both Collisions that SHOULD collide have a tick in “Generate Hit Events”.