UPROPERTY TArray with specific Blueprintclass?

Hey guys,

simple question.

How to set up an TArray (a UPROPERTY one) the way it only accepts a specifiy Blueprint Class instead of all UClass?

The following is only allowing the Baseclass of my Blueprintclass. So it wont accept my Blueprintclass.

 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Items)		TArray<AGAItem*> LootTable;

If I use the following it will accept all UClasses, instead of only the Extended Blueprint of my AGAItem-Class

 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Items)		TArray<UClass*> LootTable;

So what is the magic key? :smiley:
TSubclass?

Thanks Jack

If you are seriously using C++ as a foundation,

each subclass should be in C++, not only as a blueprint

Then you make blueprints of each subclass that you want other team members to do BP stuff for.

All key variable data should be in c++ but functions can be implemented in the BP using BlueprintImplementableEvent, if other project members want to be the ones making those functions

it will make your life very happy later on in your project’s life cycle

then you can use the C++ class in the TArray

Summary

C++ is the foundation, the skeleton, which BP can flesh out, but all key data must have a presence in the C++, classes and all key variables, and function definitions.

:slight_smile:

Rama

First of all thanks for reply.

But actually this is how I am using it.
My designer only fills out some fields with numbers, and my technical artist is using my generated events for animations and visual fx.

For this particular situation, my designer is allowed to add as many items to a loottable of a enemy. For this reason i have a struct with the item he designed (also dynamic with filling out all uproperties) and the drop chance.

It would be obvious a bad thing to hard code every item. Further more i gave my designer the class, he blueprint extend and then add it to the item field of my struct in the edior.

To prevent a non-programmer to past any blueprints in and cause crashes, I want to only allow him to put in the extended BP of my item class.

Hope this makes it a bit clearer. :smiley:

Jack

Well in the class where you are doing your core logic you can make a single property no one should mess with, that will accept your “extended BP class” that you are saying is parent of all the various items.

/** Do Not Modify */
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = ItemBPClass)   UClass* ItemBPMasterClass;

#IsA Test

and then in your cpp you can do an IsA check on any classes that your project members put into the UClass* array

//In your array loop
    UClass* EachItemClass = YourArray[Itr];
    if(!EachItemClass) continue; 
    if( ! EachItemClass->IsA(ItemBPMasterClass)) continue;

you’ve now effectively prevented against two crashes

  1. the item class was not valid at all
  2. the supplied item class was not extending the correct parent

Good?

#UBlueprint*

You can also look into making an array of actual UBlueprint*

Then you can use UBlueprint->GeneratedClass() and then use IsA on this to make sure the item BP has the correct parent class

but this means you have an array of actual UBlueprints rather than UClasses and I am not sure if that is the structure you want

it is very useful to make BP nodes that accept UBlueprint* because of how this interface is handled very nicely in UE4 BP graph editor.

#->GeneratedClass()

make sure to use UBlueprint->GeneratedClass() and not UBlueprint->GetClass()

only GeneratedClass() will return what your team members have been creating

:slight_smile:

Rama

Hey Rama,

thanks for your help. But everything u say I’ve already done.
My point was out of the view of my designer.

To catch the null point references if he past in the wrong class is basic.

My point was to automatic only show him the right classes in the drop down field, when he past it in. He should only get the right classes as options to choose from.

So if I make it i.e. APawn class, there will be only the chance for him to put in APawn in. This is what I want.

Hope it’s now clearer. Anyway thanks for the try.! :smiley:

Anyway, thanks for your help and the try :smiley:

#Unresolved, Potential Bug

Quoting Jack

"The following is only allowing the Baseclass of my Blueprintclass. So it wont accept my Blueprintclass.

 `UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Items)   
TArray LootTable`;"

ooooooooooooooooooooooooh

yea I dont know a way around that, that might even be something classified as a bug

Hopefully Epic can address the BP classes not showing up if the C++ Base class is specified

:slight_smile:

Rama

Hey jack, what did you end up doing here? Im facing a similar situation.

UPROPERTY(EditDefaultsOnly, Category = "Generation")
	TSubclassOf<class AModule> StartModule;

Works well for one element, but i cannot make an array.

UPROPERTY(EditDefaultsOnly, Category = "Generation")
TArray<AModule*> Modules;

Thanks

I didnt found a satisfying solution.

I use

TArray<UBlueprint*> LootTable;

So I have no restriction. But I told my Designer how to use it.
Sorry :frowning:

Not sure if you still need this but this worked for me:

TArray<TSubclassOf<class UClass>> ArrayName

This way they will show up filtered on lists in Editor - Parent itself and all subclasses created of it (Through blueprints or code). If that was the functionality you were seeking.