How to add a component to a spawned actor

Hello

I have a code that Spawns an actor in the scene

FActorSpawnParameters spawnParameters;	

	AActor* spawned = GetWorld()->SpawnActor<AActor>(AActor::StaticClass(), playerPosition, playerRotation, spawnParameters);

	
	if (spawned == nullptr)
	{
		//
		
	}

now i want to add one of my custom scripts to it, right after it gets spawned.

The script will calculate some numbers and move the actor in to a position.

I’m not sure if this is the right way of instantiating an actor from the c++ codes.

any help would be greatly appreciated.

Hello! You can use some code like this as example

	Component = NewObject<UInsightsSkeletalMeshComponent>(Actor);
	Component->PrimaryComponentTick.bStartWithTickEnabled = false;
	Component->PrimaryComponentTick.bCanEverTick = false;

	Actor->AddInstanceComponent(Component);

	Component->SetAnimationMode(EAnimationMode::AnimationCustomMode);
	Component->RegisterComponentWithWorld(World);