How do I get access to the GameMode class I have created from other classes?
For example, imagine you have this:
h…
UCLASS(minimalapi)
class AMyGameGameMode : public AGameMode
{
GENERATED_UCLASS_BODY()
public:
FPointSystem* PointSystem;
};
**
cpp…**
AMyGameGameMode::AMyGameGameMode(const class FPostConstructInitializeProperties& PCIP)
: Super(PCIP)
{
// set default pawn class to our character
DefaultPawnClass = AMyGameCharacter::StaticClass();
HUDClass = AMainHUD::StaticClass();
PointSystem = new FPointSystem();
}
How do you then go and access the AMyGameGameMode object…
I had a total guessage at it (Obviously it wrong):
the GetWorld()->GetAuthGameMode(); function gets the current gamemode in any AActor, keep in mind, this wont work on clients on multiplayer game, as clients in a multiplayer game cant access the gamemode becouse the only instance is in the server.
Looks like those objects are not in the current scope. Perhaps add a member to your HUD to hold a pointer to (or copy of) the game mode and fill it before entering the current state so you have data to look at.
Yes, that’s correct. It’s not there to grab yet… Hopefully someone knows why Thanks for your time though matey
Okay, I hadn’t quite grasped what vblanco was saying as it’s a new part for me… but apparently it’s not working because I am working on client… which I assume means… my pc? rather than a server… I’ll take a look at these PlayerState and GameState thingies… Any other parent declaration place?
You should never try to access objects in the constructor because, as VegasRich pointed out, there is a chance that they haven’t been constructed yet. What you should do is override the BeginPlay function and set the pointer there.
hey jimmy, GameMode only exists on the server, so first of all make sure you only call it on the server and use the command that vblanko showed you. Don’t use it in the constructor like you’re doing since it might not exist yet there, use it in the BeginPlay. I hope it works out for you