Download

C++ class instance in blueprint

Hi there!
I have a problem in understanding how exactly blueprints derived from C++ classes work. I have this situation:
I have created 2 C++ classes as shown below



UCLASS(BlueprintType, Blueprintable)
class MYPROJ_API UInnerClass : public UObject
{
GENERATED_BODY()

public:
UInnerClass();
//property meaning
UPROPERTY(EditAnywhere)
float myInnerProperty;
}




UCLASS(BlueprintType, Blueprintable)
class MYPROJ_API UWrapperClass : public UObject
{
GENERATED_BODY()

public:
UWrapperClass();
//property meaning
UPROPERTY(EditAnywhere)
TArray<UInnerClass*> myInnerPointer;
}


So basically the wrapper class contains an array of InnerClass objects.
In C++ I can create an instance of the InnerClass using


CreateDefaultSubobject<UInnerClass>

Now, since both classes are blueprintable I can create 2 blueprint classes derived by my two classes (say BP_inner and BP_wrapper). In the blueprint of the wrapper class (BP_wrapper) I can see the array of UInnerClass objects and I would like to populate this array in the editor. However the BP_inner is actually a class (as far as I can understand) so the editor does not allow me to populate the array with blueprint objects BP_inner. I would need something like creating an instance of the BP_inner class. How can I do that?

If I am not mistaken, making it a TArray<TSubclassOf<UInnerClass>> should solve your issue

Yep you are right, it works. Thank you!