[Solved] Creating custom component ignores starting position

Hi, im very new to this engine, im trying to create a custom component that adds a USphereComponent to an actor so it can interact with the gravity of other objects.
This sphere component is created in a random position and i dont know why.

this is the code used:

	collider = CreateDefaultSubobject<USphereComponent>(TEXT("GG Collider"));
	collider->SetCollisionProfileName(TEXT("GGColider"));
	collider->SetRelativeLocation(FVector(0, 0, 0));
	collider->InitSphereRadius(1500.0f);

this is the result.

Am i doing something wrong?

EDIT:

SOVLED!
InitSphereRadius was moving the component.
switching both lines did the job

collider->InitSphereRadius(1500.0f);
collider->SetRelativeLocation(FVector(0, 0, 0));

You are setting the relative location of your collider, not the world location, so yes it’s going to be relative to your static mesh component.

You can use :

collider->SetWorldLocation(FVector(0, 0, 0)); 

//or

collider->SetWorldLocation(FVector::ZeroVector); 

This will set the world location so it should then be at 0,0,0.

Ty for the answer but neither world location or relative location did the thing.
Just found out that InitSphereRadius is moving the component, so setting the position after the radius did the job :slight_smile: