UE4 C++动态的SpawnActor()
// Fill out your copyright notice in the Description page of Project Settings.
#include "OnePlayerController.h"
#include "HdsPlayer.h"
#include "OneCamera.h"
#include "OneGamemode.h"
#include "Kismet/GameplayStatics.h"
void AOnePlayerController::BeginPlay()
{
Super::BeginPlay();
AHdsPlayer* HdsPlayer = Cast<AHdsPlayer>(UGameplayStatics::GetPlayerPawn(GetWorld(),0));
FActorSpawnParameters SpawnInfo;
if (HdsPlayer)
{
//复制的路径没有_C,复制后记得加
UClass* BlueprintVar = StaticLoadClass(AOneCamera::StaticClass(), nullptr, TEXT("Blueprint'/Game/1game/Blueprint/BP_Camera.BP_Camera_C'"));
if (BlueprintVar!=nullptr)
{
AOneCamera* SpawnActor = GetWorld()->SpawnActor<AOneCamera>(BlueprintVar,HdsPlayer->GetTransform(),SpawnInfo);
if (SpawnActor)
{
UE_LOG(LogTemp,Warning,TEXT("sdfsdf"));
}
}
}
}