Download

Editable polymorphic array

I have a game I am porting to ue4. I have an Actor class that has a series of states for the state machine such as FlyState, DeadState etc… with the base class called ActorState
in my Actor class I have a list of these classes.

I’m trying to get this working in ue4 such that the states can be added to the array in the editor.

So I have something like:



UCLASS()
class DOGFIGHTS_API AGActor : public AActor
{
	GENERATED_BODY()
public:
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "GActor")
	TArray<UActorState*> ActorStateList;
};


UCLASS(abstract, BlueprintType, Blueprintable)
class DOGFIGHTS_API UActorState : public UObject
{
	GENERATED_BODY()
public:
};

UCLASS()
class DOGFIGHTS_API UDeadState : public UActorState
{
	GENERATED_BODY()
public:
};



this compiles fine. In the editor I can see ActorStateArray as a list in the editor, but I cant see DeadState to be able to put into the array element.

Is what I am wanting do-able? Or have I made some mistake?

How have you defined your various state classes? Presumably they are UCLASS and have their own properties. Try adding EditInlineNew to the UCLASS specifiers for each one that you want to be able to use (ie. not for the base class). I think you will then also need to add the Instanced property specifier to your ActorStateList property.

Edit: sorry was on mobile and didn’t scroll down your code. So yes, I believe if you do as above it should work as you want.

THANKS! that works perfectly!