Problem in casting to c++ class

Hi!
I am trying to cast a BP_HUD to a HUD type c++ class which is failing. The BP is reparented to the c++ class which I am trying to cast to. Unable to figure out why?


Here Gamemode`s HUD is set to BP_HUD which is a blueprint reparented to ObjectiveHUD which is a C++ class based on HUD. GiveWarning method is BlueprintImplementableEvent which is defined in BP_HUD. But still the cast fails.

What are you trying to do? HUDClass is the class. It’s not a pointer to an instance of it.

i.e. It’s a UClass* / TSubclassOf. Not AGameModeBase* or derivatives thereof.

I am trying to get the reference to HUD class set in game mode at that time (which at time is BP_HUD which is based on ObjectiveHUD class). This is so I can call the method defined in ObjectiveHUD class. This code is written in a different class which is called when player overlaps that trigger.

That’s the thing. You can’t do that because that is presumably a non-static member function so it needs an instance to call it on.

HUDClass is not a pointer to an instance. It is the class itself.

For example

class Example
{
    // data
};

int main()
{
    // Invalid syntax to demonstrate a point
    HUDClass = Example;   
}

So not to any instance of Example but Example itself.

OK, so is there any other way to get instance of the current HUD class in use?

Get the player controller and use GetHUD

Ok, Thanks

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