Checking for collisions with AActor

Should I be checking for collisions on the tick of my players (Characters) or should I check on the AActor. The former seems more logical, but then again, I’ve been known tog et it wrong :slight_smile:

What’s the code loop for doing this by the way? can’t seem to find the right documentation.

Depends a bit on what you are actually trying to do.

If you just want something to happen when an actor collides with the player character all you need to do is set up the collision channels. Then implement the appropriate event (Either on the player or the actor depending on what makes the most sense). The collision checks will be handled by the engine and then call the collision events when the objects collide.

Check these links for more on how the collisions work:

To expand slightly, the collision checks typically happen on a frame by frame basis as your characters move, or when you attempt to manually move using SetActorLocation and set the bool to true. I’m not sure how to manually do a collision check though. Maybe you could save the current location, movement vector, and rotation of the actor, do a SetActorLocation at the new place to check for collisions then set it back? There is probably an easier way as this sounds needlessly complicated.

1 Like

It’s for pickups… I would like to use some kind of iteration over the nearest actors… if there is a collision with the pickup actor, then add 1 to the score of my player… I’d prefer to do this in C++ as I have some logic to apply to the point system from an existing project.

Okay, I figured it out:


APickupBase::APickupBase(const class FPostConstructInitializeProperties& PCIP)
	: Super(PCIP)
{
	PrimaryActorTick.bCanEverTick = true;

        // Set up a component to collide with

	    CollisionSphere = PCIP.CreateDefaultSubobject<USphereComponent>(this, TEXT("CollisionSphereComponent"));
	    CollisionSphere->bGenerateOverlapEvents = true;
	    CollisionSphere->SetSphereRadius(20.f, false);

        // Set up a delegate function and assign it to run the CollisionOccured function (this can be named anything)

	    TScriptDelegate<FWeakObjectPtr> delegateFunction;
	    delegateFunction.BindUFunction(this, "CollisionOccured");

        // Say when you want the delegate function to be run (in this case, On overlap of components)

	    CollisionSphere->OnComponentBeginOverlap.Add(delegateFunction);

        // Make sure to set your root component to the collision thingy

	    RootComponent = CollisionSphere;

}

// Then create the function that will be called by your delegate

void APickupBase::CollisionOccured(AActor* actor)
{
    // In my case I wanted to delete the actor that the collision occurred on, so I just call this here!

       this->Destroy();
}

Easy when you know how…

I added the guide here for future ref: http://www.distal.co.uk/?p=63

Hi! guys…

I am finding to detect collision with staticmeshactor when actor is moving.

I tried jimmyt1988’s method, but it was not invoked ‘CollisionOccured’ function.

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

Is there anybody to try and success?