figured it out, basically you can treat this as making a local multiplayer game and spawning unique players, here is the code:
FString BlueprintPath = TEXT("/Game/Blueprints/RetargetedCharacters/CBP_SandboxCharacter_Manny.CBP_SandboxCharacter_Manny_C");
// Dynamically load the blueprint class
UClass* BlueprintClass = LoadObject<UClass>(nullptr, *BlueprintPath);
if (!BlueprintClass){
FString ErrorMessage = FString::Printf(TEXT("Failed to load Blueprint at path: %s"), *BlueprintPath);
GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Red, ErrorMessage);
UE_LOG(LogTemp, Error, TEXT("Failed to load Blueprint at path: %s"), *BlueprintPath);
return;
}
// Define spawn parameters
FActorSpawnParameters SpawnParams;
SpawnParams.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AdjustIfPossibleButAlwaysSpawn;
// Spawn the character
ManagedCharacter = GetWorld()->SpawnActor<ACharacter>(BlueprintClass, SpawnLocation, SpawnRotation, SpawnParams);
if (ManagedCharacter){
// Ensure the character has gravity and proper collision
UCharacterMovementComponent* MovementComponent = ManagedCharacter->GetCharacterMovement();
if (MovementComponent){
MovementComponent->SetMovementMode(EMovementMode::MOVE_Walking); // Ensure walking mode
MovementComponent->GravityScale = 1.0f; // Enable gravity
MovementComponent->bOrientRotationToMovement = true; // Orient character to movement
}
// Enable collisions for the capsule component
UCapsuleComponent* CapsuleComponent = ManagedCharacter->GetCapsuleComponent();
if (CapsuleComponent){
CapsuleComponent->SetCollisionEnabled(ECollisionEnabled::QueryAndPhysics);
CapsuleComponent->SetSimulatePhysics(false); // Ensure physics simulation is off for walking characters
}
// Make sure the character is initialized properly
ManagedCharacter->SetActorEnableCollision(true); // Ensure the actor has collision enabled
ManagedCharacter->SetReplicates(true); // Optional: Enable replication if needed
ManagedCharacter->FinishSpawning(FTransform(SpawnRotation, SpawnLocation)); // Finalize spawning process
//NEEDED FOR PlayerActor.h
SkeletalMeshComp = ManagedCharacter->GetMesh();
int32 player_index = GetWorld()->GetAuthGameMode()->GetNumPlayers();
UGameplayStatics::CreatePlayer(GetWorld(), player_index);
ULocalPlayer* local_player = GetWorld()->GetGameInstance()->GetLocalPlayerByIndex(player_index);
APlayerController* PlayerController = local_player->GetPlayerController(GetWorld());
//APlayerController* PlayerController = GetWorld()->SpawnActor<APlayerController>(APlayerController::StaticClass());
if (PlayerController){
PlayerController->Possess(ManagedCharacter);
if (PlayerController == ManagedCharacter->GetController()) {
UInputMappingContext* InputMappingContext = LoadObject<UInputMappingContext>(
nullptr, TEXT("/Game/Input/IMC_Sandbox.IMC_Sandbox"));
if (InputMappingContext){
UEnhancedInputLocalPlayerSubsystem* InputSubsystem = ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(PlayerController->GetLocalPlayer());
if (InputSubsystem){
InputSubsystem->AddMappingContext(InputMappingContext, 0); // 0 is priority
}
else {
GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Red, "InputSubsystem fail");
}
}
else {
GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Red, "IMC fail");
}
}
else {
GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Green, "Controller fail");
}
}
}
else{
GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Red, "Failed to spawn character!");
}