Why is the 'Construct Object from Class' node not accepting (any) classes?

Hi,

I have some classes that ultimately derive from UObject. Now I want to create instances of said classes within a blueprint. For objects that are not actors, there is a ‘Construct Object fom Class’ node for that purpose.
However, I only get this blueprint compilation error:

I found a post on AnswerHub mentioning that the class must be directly derived from UObject, but even then I only get this error.
What am I missing here?
Any help is appreciated :slight_smile:

Cheers,
Klaus

The class must be marked as BlueprintType, since you want to use the result in blueprint. It’s a bit silly how it lets you select classes you can’t actually use.

@Zeblote
Awesome :smiley: Works like a charm. Thanks.
And not only just with direct descendants of UObject (as the AH post suggested), but with any class ancestor that inherits from a ‘BlueprintType’ class.
Once I added ‘BlueprintType’ to my GameItem class, I can hold all kind of descendants in the array and identify them by their type :smiley:

Yeah. If you omit the ‘BlueprintType’ specifier you cant select it as a parent in the BP wizzard dialog but here the class is just available for selection.
Also the documentation for that node is quite sparse (or I didnt look in the right places).

How do you set BlueprintType? Is there a way to do that right inside Blueprints, or does it require C++?

@Rooster128 This is a C++ specifier that goes into the class definition.

Custom struct in BP:
USTRUCT(BlueprintType) // is BP type
struct FMyStruct
{
GENERATED_BODY()
UPROPERTY(EditAnywhere, BlueprintReadWrite)
FString a;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
FText b;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
FName c;
};

What if your type is blueprint without any C++? I have some components that I need to create and add at runtime, but it refuses to let me .

@crossmr

Are you using the “Add component” node?

No, because add component is component specific, you can’t pass it a class to add. I ended up creating a C++ function that can take in a class and add it.

@crossmr Is it a blueprint node? If so, could you share your implementation? I have a project with different attack styles from unit to unit (ex. melee,range,AoE) but they’d all have an “Attack” component to reference in the rest of the code.