It’s known that we can use UPROPERTY specifier Instanced
to mark a property as instanced. For example in the following code snippet, I created a class UInstancedPropertyBase
with DefaultToInstanced
UCLASS specifier and an actor class AMyActor
containing an Instanced property of class UInstancedPropertyBase.
UCLASS(Abstract, DefaultToInstanced, EditInlineNew, Blueprintable, BlueprintType)
class COMPONENTCAMERASYSTEM_API UInstancedPropertyBase : public UObject
{
GENERATED_BODY()
public:
UPROPERTY(EditAnywhere)
int Int;
UPROPERTY(EditAnywhere)
double Double;
};
UCLASS(BlueprintType, Blueprintable)
class COMPONENTCAMERASYSTEM_API AMyActor : public AActor
{
GENERATED_BODY()
public:
UPROPERTY(Instanced, EditAnywhere)
TArray<TObjectPtr<UInstancedPropertyBase>> InstancedProperties;
};
Then in the editor, I created two blueprint classes inheriting from UInstancedPropertyBase
and one blueprint class inheriting from AMyActor
.
Open the MyActor_2
blueprint and I can choose which class of Instanced_1
and Instanced_2
to instantiate. Everything goes well right now.
My question is, can I edit the instanced property in MyActor_2
through code, not just opening the blueprint and choose the class. What I want is:
- Specify the class of the instanced property, i.e.,
Instanced_1
orInstanced_2
. - Specify the internal values of the instanced class, i.e., the
Int
andDouble
values. - If it’s an array, I can add or remove one or more instanced classes.
I’m trying to access the FProperty of the CDO, but it seems infeasible because I’m trying to assign a runtime address to the instanced property of the CDO.