From Blueprint to C++ | How to decltype a C++ variable from a blueprint type passed from the editor?

As you can see from the image below I’m doing the same thing in two ways, I’m taking a pointer to the pawn spawned by default from the GameMode and assigning it to a variable, first in Blueprint, then in C++ & Blueprint together.

The Blueprint version is too long and not suited for the level of abstraction provided by blueprint (imo), but it has the advantadge of easily allowing me to say that the Player variable is of type Player_BP, therefore I get the proper interface for it.

The C++ version hides away some stuff that shouldn’t clutter the Blueprint graph to begin with (imo), but now the Player variable is hardcoded to be APawn* , therefore I need to cast it everytime to Player_BP if I want the right interface inside blueprint.

But, the GameMode hold a variable called DefaultPawnClass so it knows that my pawn class on this game mode is Player_BP, therefore how would I make it in such a way that the Player variable in the C++ code is of type * based on the blueprint type I’ve passed in the editor for the DefaultPawnClass field?

Basically I need it to be something like [FONT=courier new]decltype(TSubclassOf<Player_BP>)*[FONT=courier new] [FONT=courier new]Player;[FONT=courier new] but it should also dynamically change type if I give it another blueprint from the editor.
So how is that done? :slight_smile:

There may be a solution to actually achieve this but it would probably end up quite “hacky”. You see, a blueprint class isn’t actually class, as in it is not a C++ type. A blueprint class is a generated class which is instantiated at runtime and holds meta information about the class. C++ classes have these generated class objects as well. So in C++ you can never get the type of a blueprint class nor could you call functions or access variables with standart C++ syntax. There may be a workaround into tricking UHT to register a C++ object property with a blueprint class type, but I don’t know how or even if that would work and that wouldn’t be a very nice solution either.

Long story short, either have a blueprint child class of your game mode which can hold a variable of the blueprint class, or what I would recommend have a C++ parent class for your pawn which implements the Blueprint interface with blueprint implementable events, which can be called both from C++ and blueprints without casting.

I’ll try that, thanks :slight_smile:

hello good one question do you know how to pass the SetActorScale3D to c ++ would be very helpful