Dynamically spawned actors only collide with the player and nothing else

Hi,

I have a game where asteroids are spawned and target the player, currently they travel and delete themselves when they hit the player, however they should also delete themselves when they hit the platform the player is standing on.

This does not occur, I’ve made sure both the player and platform have Collision enable both have collision meshes etc. and have the same collision options set (see screenshots).

I use the following when setting up my asteroids.

OnActorHit.AddDynamic(this, &AAsteroid::OnCollision);

void AAsteroid::OnCollision(AActor *SelfActor, AActor *OtherActor, FVector NormalImpulse, const FHitResult& Hit)
{
    GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::, TEXT("Deleting Asteroid!"));
    Destroy();
}

Any help would be greatly appreciated.

Hello TitusONeill,

Do either of these objects have “Use Simple Collision as Complex” set for their Collision Complexity in the static mesh editor? I’ve seen problems previously with collision on meshes set to that being spawned at runtime.

If not, just to test, I’d suggest adding a box collision each of them to see if those collision bounds might collide instead of the meshes. This is mainly to rule out the logic being the problem.

Hey Matt thanks for replying,

Both have their Collision Complexity set to “Default”

Giving them both a box collision didn’t help either.

The Asteroid Objects are spawned by another actor that moves around,

AAsteroid* CreatedAsteroid = GetWorld()->SpawnActor<AAsteroid>(GetActorLocation(), FRotator(0,0,0));

They then have their Init Method Called

CreatedAsteroid->Init(target->GetActorLocation());

void AAsteroid::Init(FVector InitTarget)
{
    OnActorHit.AddDynamic(this, &AAsteroid::OnCollision);
    Target = InitTarget;
    DirectionVector = (GetActorLocation() - Target);
    DirectionVector.GetSafeNormal();
    FRotator Rotation = FRotationMatrix::MakeFromX(DirectionVector).Rotator();
    SetActorRotation(Rotation);
}

Many thanks again for your time.

Would it be possible to get a copy of your project? As this is something I haven’t seen before, this would most likely take quite a bit of back and forth with shot-in-the-dark answers. If so, you can send me a link in a private message on our forums. Heres my [profile][1]. A couple things to look at though would be the details panel after these asteroids are spawned to make sure that all of the collision is set up correctly at runtime as well. You might also want to try changing the OnActorHit to OnActorBeginOverlap just to see if it may trigger.

[1]:

Thank you for sending me the project, Titus. I’ll let you know if I find out why these asteroids won’t collide with the floor. It may be related to the delegate as they will push the floor mesh if the floor mesh is simulating physics.

Hello Titus,

I’m still looking into this issue, I just wanted to leave a comment here to let you know that I haven’t forgotten about your question.

No worries very thankful for your help.

Thank you for your patience, TitusONeill.

While I couldn’t find out exactly why the hit events aren’t working, I have found a possible workaround for you. It would involve using Overlap events instead of Hit events. If you set the asteroid to overlap the collision channel (Object Type) that the floor is set to, it should be able to fire overlap events. If you only want it to happen with the floor and not other WorldStatic objects, you could either set up a custom collision channel for the floor to use or cast to it using the actor reference.

I’ve reported the issue for the hit events but this should be a viable workaround for not. For reference, the bug number is UE-26257.

Please let me know if you run into any other issues. Have a nice day!

If you are using SetActorLocation without doing a sweep, you won’t get a blocking hit event, because it’s a teleport that is unblocked. Overlap events however would still be generated.

I got a chance to look at the sample project, and there are two issues with your setup:

  1. The SetActorLocation node has bSweep = false, meaning it will ignore collisions as it moves.
  2. The MockAsteroid BP is trying to get a hit event for the StaticMesh attached to the root component. We only get a blocking hit for the root component if you are moving the root (via SetActorLocation).

If I change the SetActorLocation to use bSweep and change the StaticMesh to be the root of the asteroid things work fine.

I got a chance to look at the sample project, and there are 2 issues with it:

  1. The SetActorLocation node has bSweep = false, meaning it will ignore collisions as it moves.
  2. The MockAsteroid BP is trying to get a hit event for the StaticMesh attached to the root component. We only get a blocking hit for the root component if it is being moved by SetActorLocation.

If I change the SetActorLocation to use bSweep and change the StaticMesh to be the root of the asteroid things work fine.

Many thanks for your time
Will put in those changes

Thanks Again