How to create a sphere collision volume?

Hi there,
I have encountered an issue when copying code from another project, where I cannot create a sphere collision volume or reference it later in the file.

AUpriseCharacter::AUpriseCharacter()
{	
	
	// Set size for collision capsule

	TriggerComp = CreateDefaultSubobject<USphereComponent>(TEXT("SphereComp"));
	TriggerComp->InitSphereRadius(5.0f);
	TriggerComp->BodyInstance.SetCollisionProfileName("Projectile");
	TriggerComp->OnComponentHit.AddDynamic(this, &AUpriseCharacter::OnHit);

	// set our turn rates for input
	BaseTurnRate = 45.f;
	BaseLookUpRate = 45.f;

	// Don't rotate when the controller rotates. Let that just affect the camera.
	bUseControllerRotationPitch = false;
	bUseControllerRotationYaw = false;
	bUseControllerRotationRoll = false;

	// Configure character movement
	GetCharacterMovement()->bOrientRotationToMovement = true; // Character moves in the direction of input...	
	GetCharacterMovement()->RotationRate = FRotator(0.0f, 540.0f, 0.0f); // ...at this rotation rate
	GetCharacterMovement()->JumpZVelocity = 600.f;
	GetCharacterMovement()->AirControl = 0.2f;

	// Create a camera boom (pulls in towards the player if there is a collision)
	CameraBoom = CreateDefaultSubobject<USpringArmComponent>(TEXT("CameraBoom"));
	CameraBoom->SetupAttachment(RootComponent);
	CameraBoom->TargetArmLength = 300.0f; // The camera follows at this distance behind the character	
	CameraBoom->bUsePawnControlRotation = true; // Rotate the arm based on the controller
	FRotator CameraBoomRotator = CameraBoom->GetComponentRotation();

	// Create a follow camera
	FollowCamera = CreateDefaultSubobject<UCameraComponent>(TEXT("FollowCamera"));
	FollowCamera->SetupAttachment(CameraBoom, USpringArmComponent::SocketName); // Attach the camera to the end of the boom and let the boom adjust to match the controller orientation
	FollowCamera->bUsePawnControlRotation = false; // Camera does not rotate relative to arm
}

void AUpriseCharacter::OnHit(UPrimitiveComponent* HitComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit) {
	
	if (isCurrentlyBeingUsed == false && OtherActor != this) {

		TriggerComp->SetSphereRadius(276.f, false);


		if (OtherComp) {
			OtherActor->setCustomTimeDilation(0.3);
			isCurrentlyBeingUsed == true;
			//Delay(10);
			OtherActor->setCustomTimeDilation(1);
			TriggerComp.Destroy();
			isCurrentlyBeingUsed == false
		}
		else() {
			OverlappedComp->setCustomTimeDilation(0.3);
			this->setCustomTimeDilation(1);
			isCurrentlyBeingUsed == true;
			Delay(10);
			isCurrentlyBeingUsed == false;
			OverlappedComp->setCustomTimeDilation(1);
			TriggerVolume->DestroyComponent();
		}
	}
	else {
		if (TriggerVolume != NULL) {
			TriggerVolume->DestroyComponent();
		}

	}
}

I get an error on the first line in which ‘TriggerComp’ is referenced (when it is created) and in every other line referencing it or editing it.

If you need anymore details please ask.
Thanks in advance.

Hi can you post your header file (.h) ? cause I don’t see a declaration for your TriggerComp.
If it’s not declared yet in your header, try adding it :

public :
USphereComponent* TriggerComp;

Hi,

Can you post your header file (.h) please ? Because I don’t see a declaration for your TriggerComp.
If it’s not declared try adding it to your header :

public:
UPROPERTY()
USphereComponent* TriggerComp;

Hope this helps :slight_smile:

Thanks! This worked. It was quite silly of me not to add the header file, but I just forgot to declare it. Thanks again!