UProperty Override

I got a class with this UProperty:

UPROPERTY(EditDefaultsOnly, Category = "Usable Actor")
TSubclassOf<class APortableActor> RequiredResource;

Then i have another sub-class (inherited) which i would like to specify a less generic type for this UProperty, such as:

UPROPERTY(EditDefaultsOnly, Category = "Usable Actor")
TSubclassOf<class AFood> RequiredResource;

In this case, the class AFood inherits from APortableActor, thats why i would like to override the UProperty, so the Level Designer would be able to specify the class type for this Blueprint, but also respecting the original’s APortableActor requirement. Although, this seems not viable. How can i achieve such behavior ?

Thanks!

You can’t override individual variables using inheritance, only virtual methods. Why does APortableActor not work for your needs? Are you just getting too many options from that?

You may want to just create a simple class called something like “AResource” which is just APortableActor which holds any members required by all your resources, and have AFood, etc inherit from that.

class AResource : public APortableActor
{
 // Resource specific methods/members.
}

class AFood : public AResource
{

}

class AMineral : public AResource
{

}

That way you can set RequiredResource to be TSubClassOf AResource and you’ll only get AFood and any other resources, rather than everything that inherits from APortableActor.

Thanks for your anwser, but the AFood class owns specific behavior, hence the need require it specifically: avoid level designers to specify wrong types through editor; but also, my class AResource owns others behaviors which i need to preserve, since its usage is managed by a controller.

Thats why i can’t degeneralize APortableActor any further. In a regular scenario, i would solve this problem using virtual methods, but if i goes this way, i’ll lose the ability to specify the required resource through the editor. Any ideas ?

I think you have really two options:

  1. You heavily comment that field in the editor, add descriptive asserts at run-time, and trust your designers not to set RequiredResource to some invalid type.

  2. You break out AFood to its own member field (since it seems to be pretty special) and then have additional resources in a separate field:

    UPROPERTY(EditDefaultsOnly, Category = “Usable Actor”)
    TSubclassOf RequiredFood;

    UPROPERTY(EditDefaultsOnly, Category = “Usable Actor”)
    TSubclassOf AdditionalResource;