Ignoring collision for a certain object in C++

You should replace your checking line with the following one:

if(OtherActor->IsA(ACollectable::StaticClass()))
{
    AddImpulse();
    Destroy();
}

Should work like that.

Hey! I am working on the projectile script that comes with the first person starter project. What I am trying to do is I am trying to get the projectile to ignore collision from a certain object (as it destroys itself as soon as it detects a UComponent). Anyone know what I can do to prevent this from happening? I already made my own little attempt, where the projectile checks what type of class the actor is running on, but I am not sure how I should implement it.

void AFirstPersonProjectile::OnHit(AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit)
{
	if ((OtherActor != NULL) && (OtherActor != this) && (OtherComp != NULL))
	{
		if (OtherActor->GetActorClass() != ACollectable) /**if the ActorClass is equal to "ACollectable", one of my classes*/
		{
		OtherComp->AddImpulseAtLocation(GetVelocity() * 100.0f, GetActorLocation());

		Destroy();
		}
	}
}

As always, I appreciate any feedback. Thank you in advance!

So how would I rewrite it if I did NOT want the Actor to be of that class?

OtherActor->IsA(ACollectable::StaticClass(false)) //?

Works, thank you very much!

So why isn’t BiggestSmile allowed to post it as an answer?

Okay sure, if you are alright with it.

#Solution

if( ! OtherActor->IsA(ACollectable::StaticClass()))
{
    AddImpulse();
    Destroy();
}

(credit to Biggest Smile too but I am posting an answer post)

Oh sorry, a typo there :slight_smile: Rama fixed code below.

awesome sharing BiggestSmile!

:slight_smile:

Rama

I am able; didn’t do so because was not sure it was what you were looking for exactly, just mark’s answer :slight_smile: