【发布时间】:2023-02-01 13:03:51
【问题描述】:
我有一个“收集器演员”,其中包含两个子演员,其他演员 1 和 2。 当我在编辑器中拖动这个 ACollectionActor 时,我必须手动选择子角色并在它们变得可见之前切换它们的网格。 但是,如果我在编辑器中拖入“OtherActor”,模型会立即显示出来。
有谁知道我的代码出了什么问题?
是的,“/Game/Models/other_model”在下面工作得很好,所以路径没有错误。
感谢任何...
CollectionActor.h
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "OtherActor.h"
#include "CollectionActor.generated.h"
UCLASS()
class IMPORTTEST_API ACollectionActor : public AActor
{
GENERATED_BODY()
public:
// Sets default values for this actor's properties
ACollectionActorActor();
UPROPERTY()
USceneComponent* Root = nullptr;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "SubActor1", Meta = (MakeEditWidget = true))
AOtherActor* SubActor1 = nullptr;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "SubActor2", Meta = (MakeEditWidget = true))
AOtherActor* SubActor2 = nullptr;
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
};
CollectionActor.cpp文件
#include "CollectionActor.h"
#include "OtherActor.h"
// Sets default values
ACollectionActor::ACollectionActor()
{
Root = CreateDefaultSubobject<USceneComponent>(TEXT("Root"));
RootComponent = Root;
FAttachmentTransformRules l_Rules(EAttachmentRule::KeepRelative, false);
Mesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Mesh"));
Mesh->AttachToComponent(Root, l_Rules);
SubActor1 = CreateDefaultSubobject<AOtherActor>(TEXT("Other1"));
SubActor1->AttachToActor(this, l_Rules);
SubActor1->SetActorLocation(FVector(-10, 0, 0));
SubActor2 = CreateDefaultSubobject<AOtherActor>(TEXT("Other2"));
SubActor2->AttachToActor(this, l_Rules);
SubActor2->SetActorLocation(FVector( 10, 0, 0));
}
// Called when the game starts or when spawned
void ACollectionActor::BeginPlay()
{
Super::BeginPlay();
}
其他Actor.cpp
#include "OtherActor.h"
// Sets default values
AOtherActor::AOtherActor()
{
Root = CreateDefaultSubobject<USceneComponent>(TEXT("Root"));
RootComponent = Root;
Mesh = CreateDefaultSubobject< UStaticMeshComponent>("Mesh");
Mesh->AttachTo(Root);
const ConstructorHelpers::FObjectFinder<UStaticMesh> MeshObj(TEXT("/Game/Models/other_model"));
Mesh->SetStaticMesh(MeshObj.Object);
}
// Called when the game starts or when spawned
void AOtherActor::BeginPlay()
{
Super::BeginPlay();
}
其他Actor.h
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "OtherActor.generated.h"
UCLASS()
class IMPORTTEST_API AOtherActor : public AActor
{
GENERATED_BODY()
public:
// Sets default values for this actor's properties
AOtherActor();
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
UPROPERTY()
USceneComponent* Root = nullptr;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
UStaticMeshComponent* Mesh = nullptr;
};
【问题讨论】:
-
从未见过
AActor被用作另一个AActor的默认子对象,我什至不知道可以编译。您可能需要考虑改用UChildActorComponent。
标签: c++ unreal-engine4 unreal-engine5