Download

Cannot set member variable of C++ type with a derived BP type.

Hello ! Here’s my issue. I have :

  • MyCharacter class derived from ACharacter. I created a blueprint MyCharacter_BP from it.
  • Weapon abstract class derived from UObject. HitscanWeapon class is derived from Weapon and Blueprintable. I created a BasicWeapon_BP derived from HitscanWeapon.

In MyCharacter, I have a protected member of type Weapon* set as EditAnywhere. It appears in the editor, but I can’t set it to BasicWeapon_BP, and no asset seems to fit.

I tried all specifiers I could think of and removing the abstract, but nothing worked. I assume I’m trying to do something stupid but I don’t understand what’s happening here.
Any insight would be appreciated. Thanks ! :slight_smile:

A Blueprint is the prototype of a class and not an object.

Weapon* pointer is a pointer to an instanced object, so you will not be able to assign blueprints to it.


You need a second variable of type TSubclassOf to store the target desired blueprint class… then use that class to spawn the actual instanced object and assign it to Weapon* pointer.

Search for ‘TSubclassOf’ with ‘NewObject’ function for examples.

1 Like

Thank you for the explanation ! It’s working now :smiley:
Have a good day !