How to find variable set in blueprint in c++?

Lets say i create a collision sphere like so in the picture . I plan to have something happen said if other actor overlaps how will i be able to find this variable in c++?

Delete the sphere from the blueprint and add this to your code:



 // 
 // in the .h File
 //
 
 UPROPERTY(VisibleDefaultsOnly, Category = Projectile)
     class USphereComponent* CollisionComp;
 
     UFUNCTION()
         void OnOverlap(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult & SweepResult);
 
 /////////////////
 ////////////////
 
 // in the .cpp File
 
 void <YourClassNameHere>::OnOverlap(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult & SweepResult)
 {
     //GEngine->AddOnScreenDebugMessage(-1, 5.0, FColor::White, FString::FString(OtherComp->GetName()));
     //GEngine->AddOnScreenDebugMessage(-1, 5.0, FColor::White, FString::FString(OtherActor->GetName()));
 }
 
 AConstructorCharacter::AConstructorCharacter()
 {
       CollisionComp = CreateDefaultSubobject<USphereComponent>(TEXT("SphereComp"));
     CollisionComp->InitSphereRadius(100.0f);
     CollisionComp->BodyInstance.SetCollisionProfileName("Collision");
     CollisionComp->OnComponentBeginOverlap.AddDynamic(this, &AYourClassNameHere::OnOverlap);
     CollisionComp->bGenerateOverlapEvents = true;
     CollisionComp->AttachTo(RootComponent);
 }
 

UnComment the GEngine Stuff to give you a debug log of what you hit

You could also create it in the editor then create a c++ pointer to the sphere exposed in blueprint and set it in the blueprint’s constructor.

Put this in your character’s class:
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = “Default”)
class USphereComponent* MySphereComp;

compile and restart the editor, then in the blueprint’s construct do:
Set MySphereComp to hello (the sphere component from your screenshot)