Download

Issue Converting Blueprints to C++

I implemented a state system. Parent (abstract) base class is in C++ (child of UObject), actual classes are blueprints. Blueprints aren’t objects though, so I have to instantiate each class once and save them into a Map<ControlInputStateBase “Class Reference”, ControlInputStateBase>. I do this in the ThirdPersonController’s Constructor.

I have five states now and my Constructor is turning into spaghetti, so I want to simplify things by converting this into C++. My problem is that I am unsure how to declare the TMap because I do not know what the C++ equivalent is to a “Class Reference” type.

My first idea was to use TSubclassOf like this:

TMap<TSubclassOf, UControlInputStateBase> stateRepository;

But it gives me five errors, e.g. ‘UControlInputStateBase’: undeclared identifier" and “UControlInputStateBase is not a valid identifier.” I also tried using an enum, but I got another error “TDefaultMapHashableKeyFuncs: unspecialized class template can’t be used as a template argument for template parameter ‘KeyFuncs’” so enums are out, too, I suppose.

Does anyone know how I can fix my current problem? Thank you in advance!

TSubclassOf is a template class (that’s why it’s prefixed with “T”). You need to change it to this:

TMap<TSubclassOf<UControlInputStateBase>, UControlInputStateBase*> stateRepository;

I recommend you use PascalCase for the letter casing of your names in C++, as that is the standard for UE coding.

(StateRepository instead of stateRepository)

EDIT: Fixed typo. The C++ equivalent to a Class Reference is a UClass, and using TSubclassOf is the right way to go.

Hope this helps!

To be perfectly honest, if you don’t understand core concepts like these, then there is no point in converting to C++. You’ll just end up with more mess. You can learn the basics of C++ in a few days.

Well I know C++. I’m not asking to make a reference to an object, that’s a piece of cake and I’ve been doing it for years. What I specifically meant was: there’s a variable type in Blueprints called a “Class Reference” I am using in my Blueprint, but you never reference “classes” in C++ - only objects (there is an Object Reference type in Blueprints as well).

C++ barely has introspection as it is, so I’m assuming Class Reference is something Epic built on top of C++ in its Unreal Header or Builder Toolkits. Although I should really read through those again.

2 Likes

Thanks! Once I made that change, I could debug the rest of the issues. (1. I forgot to add “#include ‘ControlInputStateBase.h’” and (2) I needed to make a forward declaration due to a circular dependency).

Edit: I still get this Error (but the code still reloads into the Unreal project)

LogCompile : error : Circular dependency detected for filename D:\git repositories\UE4_ThirdPersonController\Source\ThirdPersController\Public\ControlInputStateBase.h!

Adding a forward declaration of class AInputStateMachineCharacter; to fix the issue actually causes UE4.25 to crash. The project can “live” without it (ie changes are still sent to the Unreal Engine project), but I am unsure if this will cause any problems later in development.

I’m also changing my variables to use PascalCase like you suggested.