Download

Overwriting a c++ class with a blueprint derived

Got very stuck, and somewhat suprised

I have a class - should have been a struct but they are troubling me! no big deal i guess

UCLASS(Blueprintable)
class MY_API UZ_TXDATA : public UObject
{
GENERATED_BODY()

public:

UPROPERTY(BlueprintReadWrite, EditAnywhere)
	FName TXCommandType;

};

In a custom ActorComponent (UB_User is the base class of the custom Actor Component) I store this class in an array

UCLASS(Blueprintable)
class MY_API UW_UserTrigger : public UB_USER
{
GENERATED_BODY()

//---------------INTERNAL PROPERTIES

public:
UPROPERTY(EditAnywhere)
TArray<UZ_TXDATA*> MyCommandArray;

};

For development, I have been hard coding my UZ_TXDATA in c++ during the construction of my Actors, and everything is good.

in the editor, I can select the c++ actors in the scene, and access the Array from the ActorComponent, but I cant change the values stored in.

So I derived a BLUEPRINT from the UZ_TXDATA, and i can make custom values - but I cant then drag my blueprint class over the array in the editor to replace the hard coded values - the outline goes RED!

Hey there - Could you please format your code with three backticks (`) at either end?

Like this

Hi!

TArray<UZ_TXDATA*> MyCommandArray; is an array of pointers to objects of type UZ_TXDATA.
Objects are instantiations of a class/blueprint but they are not the class itself and pointers to these objects aren’t either so you cannot drag a blueprint into an array of pointers. You can instantiate objects of type UZ_TXDATA (e.g. using the Construct ... blueprint node) at runtime and then add the reference to the array or set it at a specific index.

I wonder if using BlueprintType instead of Blueprintable would make a difference there. I’m away from my computer and can’t test it :man_shrugging:t4:

I was thinking that if I derive a blueprint from the UZ_TXDATA class, then it should be allowed by polymorphism, but I guess not

The blueprints which are in Contents folder are NOT instances of the object. That’s why you cannot drag them into the array (because array accepts instances of the object).

You can imagine blueprints in Contents folder as written code. For example, If you have c++ class “A” and blueprint class “B” which derives from “A”, It’s the same as having a c++ class “B” which derives from “A”. You cannot assign “B” to an instance of “A” (e.g A* instance = B doesn’t work)

What you can do is have an array of “TSubclassOf<>” and spawn them in runtime or use “GetDefaultObject()” on them.

yeah sure, you can add objects of either type to the array (UZ_TXDATA or the derived blueprint class). But the point is that these need to be actual objects that have an address in memory, so you have something that you can have a reference/pointer to. As I said, the blueprint/class itself is just the “template”, not the actual object. Maybe @PEYMAN’s answer is more comprehensible to you, but it’s the same thing.

Im understanding the explanation…so is it possible to create instances of the blueprint without dragging them into the world as an actor

I only need the overridden variables to drag into another actor

Yes people do it all the time, you write code (whether it be C++ or Blueprint) that spawns/creates/constructs objects of classes at runtime (of the game that is). But I think you have it somehow in your head that you want to see the array already filled in the editor before you even press play.

For actors you could indeed drag them into the world and then you could select them with the dropper thing of the array and fill it like that. But UZ_TXDATA is not an actor so that’s not an option anyway. I guess you could use the construction script to create instances and fill the array that way, then you would see the entries in the editor.