Need some advice on implementing functionality in my class hierarchy

Ok, so I have a class hierarchy that consists of a base actor, and then splits off into multiple child classes, which also have other child classes. The structure may seem fairly messy, but I believe its necessary for what I’m doing.

My issue lies in the fact that I need a number of functions that are both written in c++, as well as overridable in blueprints when needed.

My original thought was to simply define functions in the base class and then override them in the classes that need them. I tried doing this a number of ways with various combinations of Uproperty parameters, but I had no luck.

For example, something like this does not work, as it can only be overridden in blueprint, or defined in the initial c++ class in which it was defined. I need to be able to call the function from possible references to intermediate classes somewhere in the hierarchy between the base class and the class i’m looking to implement the function in.

.h
UFUNCTION (BlueprintNativeEvent, BlueprintPure)
float Test();
.cpp
float ACE_EditorActorBase::Test_Implementation()
{
	return 0;
}

I then tried using an interface, and simply inheriting the interface in the classes that needed to use the functions, but this also did work since you cant use BlueprintPure parameter within an interface.

Am I missing something? is what I am trying to achieve simply not possible?

To summarise, I am looking to declare a function in a base class than I can then define further down the hierarchy in both c++ and blueprints, with the blueprint version being a pure function.

I’m fairly new to C++, so i may be overlooking a simple solution, so any help is greatly appreciated!

I was always taught that functions are different than inherited methods. But, then, I do not know how Blueprints interact with the C++ model in Unreal. I would suggest you google for connection between Blueprint and C++.

But first: Your comment that your model is messy is incorrect. In fact, when the game Unreal came out with the Unreal Engine 1.0 that was how all the creatures in the world were created. The inheritance model was quite visible in the engine editor.

Ah this is good to know that im not doing something considered bad practice :smiley:

Also it appears I was wrong, I just retried creating the following function in the base class:

baseclass.h
UFUNCTION (BlueprintNativeEvent, BlueprintPure)
float Test();

baseclass.cpp
float ACE_EditorActorBase::Test_Implementation()
{
	return 0;
}

inherited.h
float Test_Implementation() override;

inherited.cpp
float ACE_DataFloatBase::Test_Implementation()
{
	return 1;
}

With this setup, everything appears to be working correctly. They both give the correct result, as well as allowing blueprint derived classes to override into a pure function.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.