Why does not collision event invoked at Tick() function one more than?

Hi. guys.

I want to detect collision of custom actor when actor is moving at speed(v), direction(dir).

I executed rootcomponent->setworldlocation in Tick() function
Collision event was invoked at first time, but was not invoked after second execution.

I guess collision event invoked when rootcomponent stopped, if overlapped.

How can i detect collision of custom actor when actor is moving.

Whta’s wrong?

Help me. please…

//--------------------------------------------------------------------------------------------------

void Tick(float DeltaTime)
{

rootcomponent->setworldlocation(pos); // collision event(‘ReceiveActorBeginOverlap’) invoked only first time.
rootcomponent->setworldlocation(pos + FVector(0.0f, 0.0f, 10000.0f); // collision event(‘ReceiveActorEndOverlap’) invoked only first time.
rootcomponent->setworldlocation(pos + FVector(0.0f, 0.0f, -10000.0f); // collision event wat not invoked.


}

What is your class type? AActor?

my class is AActor class.

And Collision Complexity of StaticMeshActor is set ‘Use Complex Collision As Simple’.

Hey -

Collision events trigger as the bounds of one object cross the bounds of another. With SetWorldLocation() the actor is essentially being destroyed at it’s current location and recreated at the new location. Because of this the “bounds crossing” is never actually happening so the collision isn’t being detected. Instead you can try using AddActorWorldOffset() which will add a delta to the actors current location in the world. Information on how AddActorWorldOffset() is used can be found on the documentation page here: AActor::AddActorWorldOffset | Unreal Engine Documentation

Cheers

Hi!

I changed SetWorldLocation to AddActorWorldOffset. But it was not worked.
OnHit not called.

//-------------------------------------------------------------------------------------------------------------------------------

MyActor::MyActor(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
{

CollisionComponent = ObjectInitializer.CreateDefaultSubobject(this, TEXT(“CollisionComponent”));

CollisionComponent->InitSphereRadius(30.0f);

CollisionComponent->SetNotifyRigidBodyCollision(true);

CollisionComponent->SetCollisionEnabled(ECollisionEnabled::QueryAndPhysics);

CollisionComponent->SetCollisionObjectType(ECollisionChannel::ECC_PhysicsBody);

CollisionComponent->SetCollisionResponseToAllChannels(ECollisionResponse::ECR_Block);

CollisionComponent->bGenerateOverlapEvents = true;

RootComponent = CollisionComponent;

PrimaryActorTick.bCanEverTick = true;

}

void MyActor::init()
{

OnActorHit.AddDynamic(this, &MyActor::OnHit);

ActorPosition = FVector(0.0f, 0.0f, 0.0f);

}

void MyActor::OnHit()
{

MessageBox(NULL, TEXT(“Hit OK!”), TEXT(“COMMENT”), MB_OK);

}

void MyActor::Tick(float DeltaTime)

{

/----------------------------------------------------------------------------------------------------------/

RootComponent->SetWorldLocation(ActorPosition);

→ RootComponent->AddActorWorldOffset(ActorPosition - GetActorLocation());

RootComponent->SetWorldLocation(ActorPosition + FVector(0.0f, 0.0f, 10000.0f);

→ RootComponent->AddActorWorldOffset(ActorPosition + FVector(0.0f, 0.0f, 10000.0f) - GetActorLocation());

RootComponent->SetWorldLocation(ActorPosition + FVector(0.0f, 0.0f, -10000.0f);

→ RootComponent->AddActorWorldOffset(ActorPosition + FVector(0.0f, 0.0f, -10000.0f) - GetActorLocation());

/----------------------------------------------------------------------------------------------------------/

}

Engine Version : 4.6.1

OS : Windows 7

don’t know if it’s helps, i also encountered same kind of behavior, it’s like the hit event. will not fired if the recipient of the hit is the “active” actor, but it will fired when the recipient hit is the “passive” actor (or one’s that we hit). and after skim trough the CharacterMovementComponent. i think that’s the cause, because in that code we can see, they are doing a lot of trace to check the collision (to check plane, something in front actor, etc) as like the collision from receiveHit did not fired at all. CMIIW

Using a Set Relative Location node in blueprints will give me a hit result for an actor both as it is being hit by another actor as well as when it is the active actor hitting something else. Looking at the API, you should be able to get the same results with the AActor::K2_SetActorRelativeLocation() function.