Search code examples
c++unreal-engine4

Modifying ATriggerSphere radius?


I've created an instance of ATriggerSphere in my game, and placed it at my character's location, like so:

//Create activate trigger radius
activateRadiusTrigger = GetWorld()->SpawnActor<ATriggerSphere>(ATriggerSphere::StaticClass(),GetActorLocation(), GetActorRotation());
activateRadiusTrigger->SetActorHiddenInGame(false);

I need to adjust its radius now. I see that in blueprints there's a parameter under Shape that lets me change the value of "Sphere Radius", but I can't find the C++ equivalent field. Can someone tell me how that's done? Thanks!


Solution

  • If you look up TriggerSphere.h in the engine headers, you can find its public interface there. It looks like ATriggerSphere uses a collision component that you can get using GetCollisionComponent(). I'm going to assume this component is a USphereComponent, and you can call SetSphereRadius on that!

    so try:

    Cast<USphereComponent>(activateRadiusTrigger->GetCollisionComponent())->SetSphereRadius(NewRadius);