Adding Collision Sphere to AI crashes unreal

Im trying to add Collision Shere to my AI however when i add the code it causes unreal to crash straight after being launched. The code complies fine. SO far ive got projectiles hitting the Ai knocking its health down until killed. However im trying to add detect when the Ai collides with the player so i can deduct health from the player. Doing this in c++.

Hi, can you show how you adding collision sphere?

CollisionComp = PCIP.CreateDefaultSubobject(this, TEXT(“CollisionComp”));

CollisionComp->SetSphereRadius(200.0f);

CollisionComp->OnComponentHit.AddDynamic(this, &ABasicAI::onCollision);

CollisionComp->AttachTo(RootComponent);

Ive used this code in the past for another project on my character. So in theory it should work just fine

Are you adding it in your header file as well?

I found the error turns out because i didnt declare my onCollision method as a UFUNCTION it was causing the launcher to crash.