How can I spawn a sphere in C++?

This is a known limitation, and the error message is correctly pointing it out. I’m not sure why “CreateDefaultSubobject” is not allowed outside of the constructor.

I think you can use ContstructObject instead, e.g.

  //Create Component
  SphereComponent = ConstructObject<USphereComponent>(USphereComponent::StaticClass, this, TEXT("MySphereComponent"));
  if(SphereComponent) 
 {    
		// Register the component
		SphereComponent->RegisterComponent();
		
		// Attach to root component
		SphereComponent->AttachTo(GetRootComponent()); 
		  
		// or make it the rootcomponent - haven't tested this
		RootComponent = SphereComponent;
}