• UE4 C++ 常用节点


    一、打开关卡

    UGameplayStatics::OpenLevel(GetWorld(), TEXT("Map1"));

    二、退出关卡

    //退出关卡

    UGameplayStatics::GetPlayerController(GWorld, 0)->ConsoleCommand("quit");

    三、TActorIterator 遍历

    1. for (TActorIterator ActorIter(GetWorld()); ActorIter; ++ActorIter)
    2. {
    3. UKismetSystemLibrary::PrintString(GetWorld(), FString::Printf(TEXT("%s"), *ActorIter->GetName()));
    4. }

      UKismetSystemLibrary::GetAllActorsOfClass

    1. TArray OutActors;
    2. UGameplayStatics::GetAllActorsOfClass(GetWorld(), AStaticMeshActor::StaticClass(), OutActors);
    3. for (AActor* actor : OutActors)
    4. {
    5. UKismetSystemLibrary::PrintString(GetWorld(), actor->GetName());
    6. }

    四、蓝图指认类

         UPROPERTY(VisibleAnywhere,Category = UI)

               TSubclassOfActor_Instance;

    五、加载蓝图资源

            静态加载资源

    1. //静态加载模型资源
    2. MeshObj = CreateDefaultSubobject(TEXT("Mesh1"));
    3. static ConstructorHelpers::FObjectFinder TmpMesh(TEXT("StaticMesh'/Game/StarterContent/Shapes/Shape_NarrowCapsule.Shape_NarrowCapsule'"));
    4. MeshObj->SetStaticMesh(TmpMesh.Object);
    5. 静态加载类
    6. static ConstructorHelpers::FClassFinderMyActor2(TEXT("BBlueprint'/Game/Blueprints/BP_LoadTest.BP_LoadTest_C'"));
    7. MyActor = MyActor2.Class;

           动态加载资源

    1. //动态加载资源类
    2. UMaterial *mt = LoadObject<UMaterial>(nullptr, TEXT("/Game/Map/Materials/grass.grass"));
    3. UMaterial *mt = Cast<UMaterial>(StaticLoadObject(UMaterial::StaticClass(), nullptr, TEXT("/Game/Map/Materials/grass.grass")));
    4. //动态加载类
    5. Class = LoadClass<AActor>(nullptr,TEXT("Blueprint'/Game/BluePrint/BP_Test.BP_Test_C'"))
    6. 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世界设置默认的类

    1. DefaultPawnClass = AMyPawn::StaticClass();
    2. HUDClass = AMyHUD::StaticClass();
    3. PlayerControllerClass = AMyPlayerController::StaticClass();
    4. GameStateClass = AMyGameState::StaticClass();
    5. PlayerStateClass = AMyPlayerState::StaticClass();

    十二、RInterp To

    (FMath::RInterpTo(GetControlRotation(), DesireRotation, GetWorld()->GetRealTimeSeconds(), 10);

     十三、枚举

    1. UENUM()
    2. namespace MyEnum
    3. {
    4. enum MyTpe
    5. {
    6. Type1,
    7. Type2,
    8. Type3,
    9. }
    10. }
    11. //声明变量
    12. UPROPERTY(EditDefaultsOnly, Category = KWorld)
    13. TEnumAsByteCustomA;

    十四、结构体

    1. USTRUCT()
    2. struct FGameCharacterDataAttribute
    3. {
    4. GENERATED_USTRUCT_BODY()
    5. //角色名称
    6. UPROPERTY()
    7. FName Character;
    8. //角色ID
    9. UPROPERTY()
    10. int32 CharacterID;
    11. public:
    12. FGameCharacterDataAttribute();
    13. }
    14. //声明变量
    15. UPROPERTY()
    16. FGameCharacterDataAttribute CharacterDataBase;

  • 相关阅读:
    【JVM】双亲委派机制
    swagger文档部分乱码解决,swagger文档设置自动同步到yapi
    旅游APP外包开发注意事项
    网卡配置文件丢失
    [Synology]群辉 NAS Download Manager 插件配置
    1. 获取数据-requests.get()
    【Vue组件之间的三种通信】
    RabbitMQ--基础--02--原理
    Mybatis(整合spring)
    osg + pbr(三)Pbr直射光,使用回调函数替代漫游器
  • 原文地址:https://blog.csdn.net/qq_43021038/article/details/126181734