Gives me an error that “GameMode” needs a class type? I really don’t get what it means, any clues?
I’m guessing I have to use the member access operator in some way, but I’m unsure of the syntax.
I’ve been looking at this example: Pointer to C++ Classes
and tried GameMode->Gravity, but then it gives me a “Pointer to incomplete class” error? But as you can see, it’s defined in the header?
On BeginPlay you are declaring and defining GameMode again. You should define the GameMode you already declared in the header file in the constructor of your character class
Also, if you really want to declare it in your header, you should use the UPROPERTY() decorator, otherwise you will run into Garbage Collection issues.
Thanks, now I understand how declarations works and using pointers a lot better.
But I tried doing the cast in your first example (since I am going to use the variable in multiple places, I don’t want to redo the variable all over the place), but when I do that, the project crashes on loading. Suggestions?
This is what it looks like at the moment:
Brawler_Character_Player.h
UPROPERTY(EditAnywhere)
class UBrawlerGameMode *GameMode;
Also, if I try to create a pointer on the fly without declaring anything as in your example, I get these errors:
Error (active) identifier “ABrawlerGameMode” is undefined Brawler c:\Users\Gray\Dropbox\Brawler\Project Files\Brawler\Source\Brawler\Brawler_Character_Player.cpp 76
Error (active) identifier “GameMode” is undefined Brawler c:\Users\Gray\Dropbox\Brawler\Project Files\Brawler\Source\Brawler\Brawler_Character_Player.cpp 76
Error (active) no instance of overloaded function “Cast” matches the argument list Brawler c:\Users\Gray\Dropbox\Brawler\Project Files\Brawler\Source\Brawler\Brawler_Character_Player.cpp 76
Yes, I was able to reproduce the error. Sorry for the delay in responding. As a work around you could make a function to get the gamemode when needed. Something like this (this is assuming you have declared the gamemode object in your header file)
Hope this helps. It seems that you cant define it in the constructor since GameWorld() is null. You might want to try defining the GameMode variable in PostInitializeComponents().