1. 创建组件

  举个例子:

.h:
    
    //根组件
    class USceneComponent* RootScene;

    UPROPERTY(VisibleDefaultsOnly, Category = "SlAi")
        class UStaticMeshComponent* BaseMesh;

.cpp:
    
//实例化根组件
    RootScene = CreateDefaultSubobject<USceneComponent>(TEXT("RootScene"));
    RootComponent = RootScene;

    //创建静态模型组件
    BaseMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("BaseMesh"));
    BaseMesh->SetupAttachment(RootComponent);

 

2. 在引擎里寻找内容

  举个例子:

    static ConstructorHelpers::FObjectFinder<USkeletalMesh> StaticMeshFirst(TEXT
    ("SkeletalMesh'/Game/Res/PolygonAdventure/Mannequin/FirstPlayer/SkMesh/FirstPlayer.FirstPlayer'"));
    MeshFirst = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("MeshFirst"));
    MeshFirst->SetSkeletalMesh(StaticMeshFirst.Object);

 

3. 在引擎里寻找蓝图

  举个例子:

.cpp:
//获取第一人称动作蓝图
    static ConstructorHelpers::FClassFinder<UAnimInstance> StaticAnimFirst(TEXT
    ("AnimBlueprint'/Game/BluePrint/Player/FirstPlayerAnimation.FirstPlayerAnimation_C'"));
    MeshFirst->AnimClass = StaticAnimFirst.Class;