Hello!
I have class BaseWeapon with its Components (SkeletalMesh and UBoxComponent), which is spawned by WeaponComponent of Character in socket of Character’s hand.
When I walk or attack (simple sword swing animation) UBoxComponent collides with Capsule of its Owning Character and impulses from it collision create a show.
I’ve tried to add Owner and its Capsule to IgnoreActorsWhenMoving, but it didn’t work.
ABaseWeapon::ABaseWeapon()
{
PrimaryActorTick.bCanEverTick = false;
WeaponMesh = CreateDefaultSubobject<USkeletalMeshComponent>("WeaponMesh");
SetRootComponent(WeaponMesh);
BladeCollisionComponent = CreateDefaultSubobject<UBoxComponent>(
"BladeCollisionComponent");
BladeCollisionComponent->SetupAttachment(RootComponent);
BladeCollisionComponent->SetNotifyRigidBodyCollision(true);
BladeCollisionComponent->SetCollisionEnabled(ECollisionEnabled::QueryOnly);
BladeCollisionComponent->SetCollisionResponseToAllChannels(ECR_Block);
BladeCollisionComponent->OnComponentHit.AddDynamic(this, &ABaseWeapon::OnHit);
void ABaseWeapon::OnHit(UPrimitiveComponent* HitComponent, AActor* OtherActor,
UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit)
{
GEngine->AddOnScreenDebugMessage(-1, 2.0f, FColor::White, GetOwner()->GetName());
if (AActor* Character = GetOwner(); OtherActor != Character && Character)
{
OtherActor->TakeDamage(Damage, FDamageEvent(), nullptr, Character);
UKismetSystemLibrary::Delay(GetWorld(), 0.5f, LatentActionInfo);
}
}
Thank you for your help!