I have a component with a TArray
of instanced objects. When I add the component to a blueprint in the editor I can add instanced objects to the array and edit the defaults of the objects without any problems. But when I add the component to a native actor class using CreateDefaultSubobject
I can no longer add the instanced objects to the array. I can still add new members with the None
value to the array, but selecting a class from the dropdown no longer changes the value of the member.
Steps to reproduce:
- Create a new project
- Add “AIModule” to the project’s Build.cs public dependencies
- Create an actor in C++ and add the
UAIPerceptionComponent
in the constructor usingCreateDefaultSubobject
- Build an run the editor
- Inherit a blueprint from the C++ actor class
- Try to add instanced
UAISenseConfig
objects to theSenses Config
array in the perception component
UCLASS(Blueprintable)
class MYPROJECT_API ATESTACTOR : public AActor
{
GENERATED_BODY()
public:
// Sets default values for this actor's properties
ATESTACTOR();
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
UPROPERTY(VisibleAnywhere, BlueprintReadOnly)
class UAIPerceptionComponent* perceptionDebug = nullptr; // <- component
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
};
#include "TESTACTOR.h"
#include "Perception/AIPerceptionComponent.h"
// Sets default values
ATESTACTOR::ATESTACTOR()
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
perceptionDebug = CreateDefaultSubobject<UAIPerceptionComponent>(TEXT("Perception DEBUG")); // <- Adds the component
}
// Called when the game starts or when spawned
void ATESTACTOR::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void ATESTACTOR::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}