一、打开关卡
UGameplayStatics::OpenLevel(GetWorld(), TEXT("Map1"));
二、退出关卡
//退出关卡
UGameplayStatics::GetPlayerController(GWorld, 0)->ConsoleCommand("quit");
三、TActorIterator 遍历
for (TActorIterator<AStaticMeshActor> ActorIter(GetWorld()); ActorIter; ++ActorIter) { UKismetSystemLibrary::PrintString(GetWorld(), FString::Printf(TEXT("%s"), *ActorIter->GetName())); }
UKismetSystemLibrary::GetAllActorsOfClass
TArray<AActor*> OutActors; UGameplayStatics::GetAllActorsOfClass(GetWorld(), AStaticMeshActor::StaticClass(), OutActors); for (AActor* actor : OutActors) { UKismetSystemLibrary::PrintString(GetWorld(), actor->GetName()); }
四、蓝图指认类
UPROPERTY(VisibleAnywhere,Category = UI)
TSubclassOf
五、加载蓝图资源
静态加载资源
//静态加载模型资源 MeshObj = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Mesh1")); static ConstructorHelpers::FObjectFinder<UStaticMesh> TmpMesh(TEXT("StaticMesh'/Game/StarterContent/Shapes/Shape_NarrowCapsule.Shape_NarrowCapsule'")); MeshObj->SetStaticMesh(TmpMesh.Object); 静态加载类 static ConstructorHelpers::FClassFinder<AActor>MyActor2(TEXT("BBlueprint'/Game/Blueprints/BP_LoadTest.BP_LoadTest_C'")); MyActor = MyActor2.Class;
动态加载资源
//动态加载资源类 UMaterial *mt = LoadObject<UMaterial>(nullptr, TEXT("/Game/Map/Materials/grass.grass")); UMaterial *mt = Cast<UMaterial>(StaticLoadObject(UMaterial::StaticClass(), nullptr, TEXT("/Game/Map/Materials/grass.grass"))); //动态加载类 Class = LoadClass<AActor>(nullptr,TEXT("Blueprint'/Game/BluePrint/BP_Test.BP_Test_C'")) Class = Cast<UClass>(StaticLoadObject(UClass::StaticClass(), nullptr, TEXT("Blueprint'/Game/BluePrint/BP_Test.BP_Test_C'")));
六、获取GameMode
AXuHuanVSGameModeBase *MyGameMode = Cast<AXuHuanVSGameModeBase>(GetWorld()->GetAuthGameMode());
七、获取Pawn
AMyPawn *MyPawn = Cast<AMyPawn>(GetWorld()->GetFirstPlayerController()->GetPawn());
八、获取GameState
AGameState *MyState = Cast<AGameState>(GetWorld()->GetGameState());
九、获取PlayerController
AMyPlayerController *MyPlayerController = Cast<AMyPlayerController>(GetWorld()->GetFirstPlayerController());
十、设置UE4世界设置默认的类
十二、RInterp To
(FMath::RInterpTo(GetControlRotation(), DesireRotation, GetWorld()->GetRealTimeSeconds(), 10);
十三、枚举
UENUM() namespace MyEnum { enum MyTpe { Type1, Type2, Type3, } } //声明变量 UPROPERTY(EditDefaultsOnly, Category = KWorld) TEnumAsByte<MyCharacterType::MyType>CustomA;
十四、结构体
USTRUCT() struct FGameCharacterDataAttribute { GENERATED_USTRUCT_BODY() //角色名称 UPROPERTY() FName Character; //角色ID UPROPERTY() int32 CharacterID; public: FGameCharacterDataAttribute(); } //声明变量 UPROPERTY() FGameCharacterDataAttribute CharacterDataBase;
版权声明:本文为CSDN博主「飞起的猪」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_43021038/article/details/126181734