Download

[Code Feature] New Property Specifier 'GeneratedForDerived'

I noticed that one of the biggest problems when deriving from a pre-existing class is not knowing which member function is the primary one to use. Unreal fortunately done this for some classes by showing certain member functions by default. I feel like this increases productivity as you don’t waste time trying to remember or find specific critical functions. Example:

AActor implements BeginPlay(), Tick() and the constructor by default. It also specifies a general implementation for the constructor by including a bPrimaryActorTicks = true or something.

The problem is that this, I believe, is hard-coded. What I’m suggesting is a general solution; in the function definition you put ‘GeneratedForDerived’.



.h
UFUNCTION(GeneratedForDerived)
APawn* FindPawn(FVector Location, FVector Radius); // Placeholder function, could be anything important to implement for derived classes.


In the implementation you will put two versions of the function; one is the function you intend to use now, and one is the function that will be automatically generated for any derived classes when ‘New Class’ is clicked in Unreal.



.cpp
APawn* SomeClass::FindPawn(FVector Location, FVector Radius) { ... Do calculations return something ... }
APawn* SomeClass::FindPawn_DerivedImplementation(FVector Location, FVector Radius) { ... Anything I put here is generated along with this function signature in a derived class ... }


The ‘_DerivedImplementation’ portion is just to let the engine know what function implementation to generate for the derived class. If the function is marked virtual in the base class then the derived class should automatically append override.

This isn’t really a necessary feature for the classes I make myself as I already know the flow of data through them, but I think it will help a lot in the engine if it was used for the main member functions in most Unreal classes.
Like when deriving from UBTTask_BlackboardBase it should automatically generate the ‘EBTNodeResult::Type ExecuteTask(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory) override’ function so I don’t have to go look up the signature.

I don’t think this is ABSOLUTELY necessary, but I feel it’ll make life easier in some cases.