Is there a way to define a property in C++ that needs to be implemented by an inherited Blueprint class?

With a Widget I can create a C++ base class and do something like this:

UPROPERTY(BlueprintReadWrite, meta = (BindWidget))
UImage* PreviewImage;

so that a Widget BP that inherits will need to have a UImage called PreviewImage to compile.
Is there a way to do something similar, but for an AActor subclass?

I would like to have access to a static mesh property, but have the blueprint implementation define the exact static mesh. The C++ implementation wouldn’t need to add the static mesh.
Something like this:

UPROPERTY(VisibleAnywhere, Category = "Presentation")
UStaticMeshComponent* StaticMesh;

Thanks for the help!

I’m not sure I’ve understand, but I’m supposing the blueprint derives from the c++ class and you want to set the mesh from the blueprint.
The blueprint doesn’t have to “implement” nothing, because that is just a property, properties are not implemented, methods do.
You will have to create the StaticMesh in the c++ class (with CreateDefaultSubobject) or else the blueprint will crash if it tries to access it.
Do you want do set the 3d model mesh from the blueprint? If that’s the case, just make the property visible/editable in blueprint and then you will have the static mesh properties available. Then you can set the mesh.
The ACharacter class does this.

Of course I might be completely wrong!

Yes. This is fairly common. However, I don’t think there’s a way to mark it as required (similar to the abstract keyword in C++).

Two ways you can do this.
The first is to mark the UPROPERTY as BlueprintReadWrite. This allows you to open up the Construction Script and set the value of the StaticMesh variable.
Another way is to mark the UPROPERTY with some EditX. I forgot exactly which Edit it is. It’s either EditDefaultsOnly or EditInstanceOnly. (One of them allows you to select an instance of an object within the Properties tab (what you want), the other allows you to select the type of object (kinda like TSubclassOf)).

3 Likes

You can override the virtual IsDataValid method to require your subclasses to populate that property

1 Like

Thank you for the reply! Dynamiquel’s answered it (I don’t think I worded my question great!) A UPROPERTY with EditDefaultsOnly worked.

This worked, thank you!