Predefine a TArray to be used in other classes?

I’m not sure how to properly describe this problem and I’m open to other methods to achieve the same effect. Basically I want to create different TArray lists that hold blueprint classes.

TArray<TSubclassOf<SomeClass>> MyCollection;

I want to predefine what is contained in these lists, so I can have a “collection” of related blueprints that get passed to different character instances in my level. Each Character would contain a List of collections.

TArray<SomeType> Collections;

In my level I would then select the instance of say Character1, and edit the “Collections” list to contain say MyCollectionA and MyCollectionB. Then Character2 might have MyCollectionC.

I basically have this problem that different Characters need different lists of things, and I want to bundle those things into related lists so I don’t have to individually select each blueprint for every single character instance. What is the best way to do this?

I tried creating a USTRUCT in a header file, but looking at USTRUCT() specifiers, they can only have BlueprintType, not Blueprintable, so I don’t know how I would create a blueprint of the USTRUCT and populate it with predetermined values to create my collection list. Do I need to create a simple class that contains The TArray<> of blueprints, then create a blueprint that extends that class, populate the TArray, and use that blueprint as my collection type? Or is there a better way to do this?

Thanks!

I think you could use an Interface with the TArray instead of a Simple Class but yeah structs sadly don’t work with blueprint nicely.

I just ended up creating a C++ class that just holds a TArray<TSubclassOf<MyObject>>. Made the class Blueprintable, and the array EditDefaultsOnly. This let me create blueprints and predefine the collection array.

Added a EditInstaceOnly TArray<TSubclassOf<MyCollectionClass>> in my character class. This lets me do what I want, although I can’t help but feel like there is a better way to do this. Oh well, thanks for the help!

1 Like