Does IgnoreActorWhenMoving() actually work?

Hi,

I have a Ship Pawn (Physically represented by a UStaticMeshComponent, Collision = BlockAll) that shoots projectiles (Actors with a SphereComponent as its root, Collision = BlockAll). Since the muzzle of the guns are actually inside the hit box of the ship, it crashes into its own Bullets everytime I shoot.

I read about IgnoreActorWhenMoving() and thought that this sounds like just what I needed. I wrote a BeginPlay() override in my Projectile Actor that looks as follows:

void AProjectile::BeginPlay()
{
	Super::BeginPlay();

	if(AActor* Owner = GetOwner())
	{
		if(PhysicalRepresentation)
		{
			// Ignore my owner
			PhysicalRepresentation->IgnoreActorWhenMoving(Owner, true);
		}

		if(UPrimitiveComponent* Root = Owner->GetRootPrimitiveComponent())
		{
			// Owner should ignore me
			Root->IgnoreActorWhenMoving(this, true);
		}
	}
}

But they still collide! I double checked that GetMoveIgnoreActors() returns the correct actors. It is not an option for me to set one or both of them to “OverlapAll” or “NoCollision” since I want them to collide with everything else.

I tried doing the same thing in Blueprints with exactly the same effect (which is none at all).

Edit: Here is my AProjectile Constructor (Actually much simpler than the UT projectile you posted…):

AProjectile::AProjectile()
{
	PrimaryActorTick.bCanEverTick = false;

	PhysicalRepresentation = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Sphere"));
	PhysicalRepresentation->SetCollisionProfileName(TEXT("BlockAll"));
	RootComponent = PhysicalRepresentation;

	ProjectileMovement = CreateDefaultSubobject<UProjectileMovementComponent>(TEXT("ProjectileMovement"));
	ProjectileMovement->bRotationFollowsVelocity = true;
	ProjectileMovement->MaxSpeed = 1000000.f;
	ProjectileMovement->SetUpdatedComponent(PhysicalRepresentation);
	
	InitialLifeSpan = 3.f;

	this->bReplicates = true;
	this->bReplicateMovement = true;

	NetCullDistanceSquared = 10000000000.f;		///< Visible up to 1000m away (seems to be sufficient)
}

Any suggestions are greatly appreciated.

David

I had the same problem with my grenades projectiles. Even when IgnoreActorWhenMoving was set to pawn that holds grenade they still collide. It turned out that logic in the projectile works fine, the problem was caused by pawn movement component which sweeped that projectile and run depenetration logic.

Besides beginplay function may be to late to set ignoring actors. I would test setting ignore actor between

CurrentGrenadeInTheHand = (UGameplayStatics::BeginSpawningActorFromClass(this, GrenadeInventory[CurrentSelectedGranadeType].GranadeClass, SpawnTM, true));

CurrentGrenadeInTheHand ->MovementComp->UpdatedPrimitive->IgnoreActorWhenMoving(this, true);

UGameplayStatics::FinishSpawningActor(CurrentGrenadeInTheHand, SpawnTM);

Thanks for your suggestion. I tried doing it between BeginSpawningActorFromClass and FinishSpawningActor, but nothing changed.

Regarding the first part of your answer, how did you solve that? I don’t have a Character, so I don’t have a CharacterMovementComponent…

In my case the Character capsule collides with grenades.
Can you post your AProjectile constructor, I would like to compare it with UT projectile components/colliders setup:
https://github.com/EpicGames/UnrealTournament/blob/clean-master/UnrealTournament/Source/UnrealTournament/Private/UTProjectile.cpp

Sure, please have a look at my edit.

Don’t know how to help you, but I would reconsider using PhysicalRepresentation as static mesh component with blockall collision profile because this will always report a collision.

It seems that IgnoreActorWhenMoving is working only when you don’t have physically based collider and the projectile is using Projectile movement component.

But if you insist on the static mesh collider what about disabling collision for certain amount of time and enable them when the projectile fly away from instigator?

Hi David,

I know this is a very old question, but I couldn’t find an easy answer to this on any other questions, so I thought I should answer for posterity’s sake.

The API page for the IgnoreActorWhenMoving call says

“Components on the other Actor may also need to be told to do the same when they move.”

I just coded up an example of an actor spawning a projectile, and I called IgnoreActorWhenMoving on the projectile’s static mesh, but I also used MoveIgnoreActorAdd on the Actor responsible for spawning the projectile to make sure they don’t collide with each other.

	ARadianceProjectile* proj = GetWorld()->SpawnActor<ARadianceProjectile>(Location, Rotation, SpawnInfo);
	this->GetControlledPawn()->MoveIgnoreActorAdd(proj);

I have that code in the Controller for the actor responsible for spawning the projectile, and it seems to work great.

Hope this is helpful.

This is certainly a hard topic to find a lot of solid documentation about. Do you have a full example of all the code involved in this? It just seems to be little snippets here and there. Makes it hard to piece everything together. If I have a gun that shoots a projectile, this code will add the pawn holding it to the ignore actor list? Usually I set the gun not to block anything since i don’t want it to act as a shield. But i have issues with forward momentum causing bullets to hit the player. Do I need to just include the ignore actor stuff from the original question?