Download

How to add types and classes in existing engine modules?

Hi, I have been trying to add a test class to one of the engine modules, in a public header, using the standard method to expose the new class/function to other modules.
However, every time I try to rebuild the engine from the source after being edited, build fails and all sort of errors appear, among them multiple errors stating there’re redefinitions of classes in the header that was edited. Other errors are in totally different files where some macros render “undefined identifier” to the compiler, to name a few other errors.

I started by cloning, and forking the branch 4-27, and it is correctly built if I don’t make any edit; Once I add anything to the source, it is not buildable.

Here is the class I added to the header WindowsApplication.h (a public header in the module ApplicationCore):

//..
//..untouched code lines.
//..
#define WINDOWS_APPLICATION_H_MY_PROJECT_ADDITION 1
//..
//..other code lines(untouched).
//..
//These lines are added to the existing class FWindowsApplication:
class APPLICATIONCORE_API FWindowsApplication
	: public GenericApplication
	, public IForceFeedbackSystem
{
#if WINDOWS_APPLICATION_H_MY_PROJECT_ADDITION 
	friend class FXInputProxy_;
#endif // WINDOWS_APPLICATION_H_MY_PROJECT_ADDITION 
//..
//..other code lines(untouched).
//..
}
#if WINDOWS_APPLICATION_H_MY_PROJECT_ADDITION 
class APPLICATIONCORE_API FXInputProxy_
{
public:
	FXInputProxy_() = delete;
	FXInputProxy_(FWindowsApplication* InWinApp);
private:
	FWindowsApplication* WinApp = nullptr;
	XInputInterface* XInput = nullptr;
public:
	void Poll(short InRaw[]);
};
#endif // WINDOWS_APPLICATION_H_MY_PROJECT_ADDITION

Then inside the source code of the header (WindowsApplication.cpp),
I added those lines of code:

#if WINDOWS_APPLICATION_H_MY_PROJECT_ADDITION
FXInputProxy_::FXInputProxy_(FWindowsApplication* InWinApp)
{
//Function not yet implemented!
}
void FXInputProxy_::Poll(short InRaw[])
{
//Function not yet implemented!
}
#endif // WINDOWS_APPLICATION_H_MY_PROJECT_ADDITION

I don’t know an answer, especially since I can’t see the errors, but I’m not sure that UBT or UHT can handle files with multiple classes in them (they may be able to, I don’t know), but I am curious why you’re trying to extend FWindowsApplication to do something.

I will keep trying different other things tomorrow, and I will post the errors if persisted.
As to why I am doing this, it is a long story, the short of it is that I need to update and poll inputs from outside the game thread completely. The final code might not need an edit to a specific platform implementation (windows in this case), but I am working on Windows now, and I want to be able to test many things to understand how the sausage is made.

They definitely can. I do all my native changes directly and skip any wizards or editor tools to add files or classes. Lots of my headers include multiple classes in them. I have run into problems with interfaces and a class implementing that interface being in the same header. Still not sure why.

good to know!

what i’d probably consider is creating a Subsystem ( Programming Subsystems | Unreal Engine Documentation ) and running another thread in that, outside of game thread, and doing your input checking in there. My actual experience with writing multi-threaded code in Unreal however is currently exactly zero. I’ve read some multi-threaded code, but have never wrote it. So my idea may not be workable, not sure.

The answer was actually pretty simple. The class XInputInterface is not included, and it needs a forward declaration prior to using. Adding the keyword ‘class’ resulted in success of build.