c++获取GameMode
if(GetWorld()) {
auto gamemode = (ASomeGameMode*)GetWorld()->GetAuthGameMode();
}
或者
ASomeGameMode* gm = (ASomeGameMode*)GetWorld()->GetAuthGameMode();
获取所有actors
https://answers.unrealengine.com/questions/289453/get-all-actors-of-class-in-c.html
获取controller
UGameplayStatics::GetPlayerController(GetWorld(), 0);
或者GetWorld()->GetFirstPlayerController()
切换level
void ACodeLevelChangeCharacter::SwapLevel()
{
UWorld* TheWorld = GetWorld();
FString CurrentLevel = TheWorld->GetMapName();
if (CurrentLevel == "ThirdPersonExampleMap")
{
UGameplayStatics::OpenLevel(GetWorld(), "Level2");
}
else
{
UGameplayStatics::OpenLevel(GetWorld(), "ThirdPersonExampleMap");
}
}
查找object,actor
for ( TObjectIterator<USkeletalMeshComponent> Itr; Itr; ++Itr )
{
// Access the subclass instance with the * or -> operators.
USkeletalMeshComponent *Component = *Itr;
ClientMessage(Itr->GetName());
}
for (TActorIterator<AStaticMeshActor> ActorItr(GetWorld()); ActorItr; ++ActorItr)
{
// Same as with the Object Iterator, access the subclass instance with the * or -> operators.
AStaticMeshActor *Mesh = *ActorItr;
ClientMessage(ActorItr->GetName());
ClientMessage(ActorItr->GetActorLocation().ToString());
}
Unreal中的构造函数,只在生成到场景中的时候执行,启动游戏是不会执行构造函数的
对于不是主Controller绑定的actor,想要获取输入的方法