How do I create some abstract type in c++ that I can edit in the editor

I’d like to be able to create a base Action class and have an array of them in a character that I can edit inline in the editor.

This seems pretty straightforward and a very common pattern but I’ve tried with structs and UObjects and I can’t seem to do this.

With the UObject implementation it’s an array of empty fields and there’s not way to add instances of different actions to them. With structs there’s no way of having a list of different types of structs.

This code is just a simplified example of what I’m trying to do.

class Action 
{
public:
   int cost;
};

class ShootAction : public Action
{
public:
    int rof;
};

class ExplodeAction : public Action
{
public:
    float radius;
};

class Character
{
public:
    array<Action*> actions;
}

Here’s the snipped of the actual code I’m testing with

UCLASS(abstract, BlueprintType)
class UTopBaseState : public UObject
{
public:
	GENERATED_UCLASS_BODY()
		
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Default)
	FName StateName;
};

UCLASS(BlueprintType)
class UTopState : public UTopBaseState
{
public:
	GENERATED_UCLASS_BODY()

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Default)
	int32 StateType;
};

UCLASS(Blueprintable)
class ATopTestPawn : public APawn
{
	GENERATED_UCLASS_BODY()

	UPROPERTY(Category = GamePlay, EditAnywhere, BlueprintReadWrite)
	TArray<UTopBaseState*> States;
}

Hey nykwil-

You’ll want to add the line UPROPERTY(EditAnywhere) above the array in the character class. This will expose the variable to the editor and allow you to make changes in editor. Here’s a link that gives more information on property specifiers like ‘EditAnywhere’: Unreal Engine UProperties | Unreal Engine 5.1 Documentation

Cheers

Thanks for the reply, I should have been more clear that it’s just pseudo code.

Unless you spawn the objects/actors elsewhere and insert them into the list by referencing the actor instance, an array of USTRUCTs is how you’d go about populating lists inline. eg:

USTRUCT(BlueprintType)
struct FAction 
 {
 public:
   UPROPERTY(EditAnywhere, BlueprintReadWrite)
   INT32 cost;
 }

USTRUCT(BlueprintType)
struct FShootAction : public FAction
 {
    GENERATED_USTRUCT_BODY();

     UPROPERTY(EditAnywhere, BlueprintReadWrite)
     INT32 rof;
 }

... TArray<FShootAction>

Thanks Grogger. The array should be TArray to support different actions but I couldn’t figure out a way to have pointers to structs in a uproperty.

Hopefully the question is clearer now.

It’s unfortunate, but it isn’t possible to have a pointer to a struct in a uproperty.

Having a TArray of object/actor pointers is the only other solution (I can think of), but you won’t be able to populate the actor inline as you can with a struct.

I believe this should be possible. I think you need to add the ‘EditInlineNew’ specifier in the UCLASS macro for UTopBaseState, and possibly the ‘Instanced’ specifier in the UPROPERTY macro of your array. Check class specifiers and property specifiers in the API reference for details on these.

Now the bad news.

  1. There appear to be some issues - see my question and the other question I linked to from it.
  2. I don’t know if the fact that you’re using an array would further complicate things.