Announcement

Collapse
No announcement yet.

Getting access to the GameMode

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • replied
    Yeah I had a problem doing it this way.

    Click image for larger version

Name:	wadawd.png
Views:	1
Size:	10.0 KB
ID:	1056498

    So you have to declare the template type:

    Code:
    	GameState = Cast<AMainGameState>(world->GetGameState<AMainGameState>());
    and then you may aswell get rid of the Cast...

    However, even with the Cast it doesn't seem to return the GameState set up in the GameMode

    Related: https://answers.unrealengine.com/que...urns-null.html ?
    related: https://forums.unrealengine.com/show...etworking-test

    errr.... I had a typo... YEHAAA IT WORKs.. THANKS ALL... Beers for ALL
    Last edited by jimmyt1988; 09-09-2014, 08:01 PM.

    Leave a comment:


  • replied
    Code:
    GameState = Cast<AMainGameState>(world->GetGameState()); // ?

    Leave a comment:


  • replied
    My GameState is empty.. Any ideas what might be failing?

    I am setting the class up in the gamemode:

    Code:
    GameStateClass = AGameState::StaticClass();
    and then inside my huds BeginPlay I am calling

    Code:
    UWorld* world = GetWorld();
    	GameState = world->GetGameState<AMainGameState>();

    Leave a comment:


  • replied
    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

    Leave a comment:


  • replied
    Kumppi, you're right!!! It does end up deriving from AActor... Thanks for slapping me down like the noob I am, hangon lemme see if this works now..

    Well looooooky here... It no longer crashes... Now I've got to get this GameState working instead which I didn't realise I was supposed to use instead.
    Last edited by jimmyt1988; 09-09-2014, 06:52 PM.

    Leave a comment:


  • replied
    Isn't AHUD derived from AActor? If so it should have the BeginPlay function. Weird. Well game mode definitely has it.

    Leave a comment:


  • replied
    Unfortunately that will not work bro... Once again though, cheers for having a try!!!

    Leave a comment:


  • replied
    Code:
    void ATofuGameGameMode::StartPlay()
    {
    	DefaultPawnClass = ATofuGameCharacter::StaticClass();
    	HUDClass = AMainHUD::StaticClass();
            HUDClass->GameMode = this;
    }
    maybe? Hopefully?

    Leave a comment:


  • replied
    Kumppi... The Hud doesn't have a BeginPlay, are you thinking of StartPlay with the GameMode? If so, I have moved into this now:

    Doesn't make a difference unfortunately... but thanks for the warning.


    Code:
    ATofuGameGameMode::ATofuGameGameMode(const class FPostConstructInitializeProperties& PCIP)
    	: Super(PCIP)
    {
    	// set default pawn class to our character
    }
    
    void ATofuGameGameMode::StartPlay()
    {
    	DefaultPawnClass = ATofuGameCharacter::StaticClass();
    	HUDClass = AMainHUD::StaticClass();
    }

    Leave a comment:


  • replied
    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.

    Leave a comment:


  • replied
    Is your HUD object global? If so, perhaps you can have the game mode register itself with your HUD when it comes up.

    Leave a comment:


  • replied
    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?
    Last edited by jimmyt1988; 09-09-2014, 05:58 PM.

    Leave a comment:


  • replied
    Then somehow it's not being set. Look at your screenshot - it's NULL....

    I see in your HUD constructor you try to get the game mode and set it - my guess is that it doesn't exist at that point.

    Leave a comment:


  • replied
    Isn't this what I have?... You can see GameMode is of Type ATofuGameMode... and it's a property of HUD:


    Code:
    /**
     * 
     */
    UCLASS()
    class TOFUGAME_API AMainHUD : public AHUD
    {
    	GENERATED_UCLASS_BODY()
    public:
    	TSubobjectPtr<UHUDElementComponent> TofuPoints;
    	virtual void DrawHUD() override;
    	ATofuGameGameMode* GameMode;
    };

    Leave a comment:


  • replied
    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.

    Leave a comment:

Working...
X