Spawning Character in Runtime

When I am spawning a character during game-play → my character completely ignores collisions as well as failing to Walk at open spaces (completely flat ground, and sometimes appears to fly :open_mouth: ).
However if placed in world by editor everything works fine.

Any ideas?

Relevant Part of C’tor

SetRootComponent(GetCapsuleComponent());

m_ActionManagerComponent = CreateDefaultSubobject<UActionManagerComponent>(TEXT("ActionManagerComponent"));
m_timerManagerComponent = CreateDefaultSubobject<UTimerManager>(TEXT("TimerManagerComponent"));
m_combatComponent = CreateDefaultSubobject<UBaseCombatComponent>(TEXT("Combat Component"));

m_onHitBloodEmitter = CreateDefaultSubobject<USphereComponent>(TEXT("OnHitEmmiterSphere"));
PrepareSphere(m_onHitBloodEmitter);
m_onHitBloodEmitter->SetupAttachment(GetCapsuleComponent());

GetCapsuleComponent()->OnComponentHit.AddDynamic(this, &ACBaseUnitCharacter::OnHit);
GetCapsuleComponent()->OnComponentBeginOverlap.AddDynamic(this, &ACBaseUnitCharacter::BeginOverlapEvent);

m_animationSoundComponent = CreateDefaultSubobject<UDynamicAudioComponent>(TEXT("AnimationSoundComponent"));
m_animationSoundComponent->SetupAttachment(GetCapsuleComponent());

m_actionSoundComponent = CreateDefaultSubobject<UDynamicAudioComponent>(TEXT("ActionSuondComponent"));
m_actionSoundComponent->SetupAttachment(GetCapsuleComponent());

m_otherSoundComponent = CreateDefaultSubobject<UDynamicAudioComponent>(TEXT("OtherSoundComponent"));
m_otherSoundComponent->SetupAttachment(GetCapsuleComponent());

//UCapsuleComponent* collisionCapsule
m_hardCollisionCapsule = CreateDefaultSubobject<UCapsuleComponent>(TEXT("HardCollisionComponent"));
m_hardCollisionCapsule->SetupAttachment(GetCapsuleComponent());
 m_hardCollisionCapsule->OnComponentHit.AddDynamic(this, &ACBaseUnitCharacter::OnHardHit);

SetDefaultHardCollisionPreset(m_hardCollisionCapsule);

m_selectionBounds = CreateDefaultSubobject<UBoxComponent>(TEXT("SelectionBox"));
m_selectionBounds->SetupAttachment(GetCapsuleComponent());
m_selectionBounds->SetCollisionResponseToAllChannels(ECR_Ignore);
m_selectionBounds->SetCollisionResponseToChannel(ECC_GameTraceChannel3, ECR_Block);
m_selectionBounds->SetCanEverAffectNavigation(false);
m_selectionBounds->bGenerateOverlapEvents = false;

In Begin Play:

m_animationSoundComponent->AttachToComponent(GetCapsuleComponent(), FAttachmentTransformRules(EAttachmentRule::SnapToTarget, false));
m_actionSoundComponent->AttachToComponent(GetCapsuleComponent(),    FAttachmentTransformRules(EAttachmentRule::SnapToTarget, false));
m_otherSoundComponent->AttachToComponent(GetCapsuleComponent(),     FAttachmentTransformRules(EAttachmentRule::SnapToTarget, false));

m_selectionBounds->AttachToComponent(GetCapsuleComponent(),         FAttachmentTransformRules(EAttachmentRule::SnapToTarget, false));

//m_hardCollisionCapsule->AttachToComponent(GetCapsuleComponent(),    FAttachmentTransformRules(EAttachmentRule::SnapToTarget, true));
m_hardCollisionCapsule->AttachToComponent(GetCapsuleComponent(), FAttachmentTransformRules(EAttachmentRule::KeepRelative, true));

In BP class there is nothing much it just setting Default values etc…

Here is how I spawn it:

Hello ColdSteel48,

Can you please provide me the entire .cpp and .h File of this Character class?

Thanks!

Hello NicolasMond,

The entire CPP is too huge.

However I found the problem: (I actually found many)

  1. In BP of the character he Movement Component was set to NavWalk - which as I can see ignore collisions.

So BuG#1 when I drag and drop the character to world - it uses OhyWalking for some reason, but when spawned dynamically it is nav walking.

  1. Detour Crowd Bug…
    It appears that Detour Crowd completely ignore NavigationQuerryFters when it tries to avoid
    other pawns - and this is a huge bug…
    It makes the while detour useless…
    Since it supports only 1 agent (navmesh) it also unreliable in terms of filters…

Please note that when you are doing MoveTo it will respect the filter if specified or has default
but when the CrowdManager will repath upon collision with some other agent
no filters applied.

  1. NavMesh Walking - is unreliable and stuck every time it wants to climb up hill even if the
    hill is 100% marked as walkable my recast… and I assume because of the trace condotion
    that traces only down - for nav poly.