and this is my AObstacleQuestGameMode.h file of gamemode with these variables
// Copyright Epic Games, Inc. All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/GameModeBase.h"
#include "ObstacleQuestGameMode.generated.h"
UCLASS(minimalapi)
class AObstacleQuestGameMode : public AGameModeBase
{
GENERATED_BODY()
public:
AObstacleQuestGameMode();
UPROPERTY(EditAnywhere, Category="Class Type")
TSubclassOf<UUserWidget> StartTimerClass;
UPROPERTY(VisibleInstanceOnly, Category="Class Type")
class UStartTimerWidget* StartTimerWidget;
protected:
virtual void BeginPlay() override;
};
The widget doesn’t appear when the game is started. idk why this happens. The variable in the class name is set in the blueprint child of the gamemode file.
I tried the same logic in a triggerbox actor and on its onbeginoverlap function. It works. follow the same steps twice, copied and pasted the code to make no mistake, double checked everything and everytime the widget only appears when i overlap my character on the trigger box, not when the game begins. This leaves me confused as am i supposed to do something addition for gamemode cpp file as the steps i took for this widget to appear works in triggerbox cpp but not in the gamemode cpp.
Gamemode only exist on server, not on client. Could be the issue, else you’ll need to research more into this with google or here on forums. I havent messed with gamemode much myself but remember this being stated.
Quoted from the link below:
Game State
The Game State is responsible for enabling the clients to monitor the state of the game. Conceptually, the Game State should manage information that is meant to be known to all connected clients and is specific to the Game Mode but is not specific to any individual player. It can keep track of game-wide properties such as the list of connected players, team score in Capture The Flag, missions that have been completed in an open world game, and so on.
Game State is not the best place to keep track of player-specific things like how many points one specific player has scored for the team in a Capture The Flag match because that can be handled more cleanly by Player State. In general, the GameState should track properties that change during gameplay and are relevant and visible to everyone. While the Game mode exists only on the server, the Game State exists on the server and is replicated to all clients, keeping all connected machines up to date as the game progresses.
if a make a separate class, lets say WidgetLogic.cpp that has the widget functions defined in it and only call the functions from this class into gamemode, will that work?
i honestly couldnt say, i’ve made my project fully in Blueprint with little C++ usage aside from plugins. Just remember the gamemode is only on the server so a client can never access it, in blueprint the cast to it would always fail. Serverside calls to it can definitely access it, but not client.
If you have something like a reference to the widget on the gamemode and run a serverside event to get that variable or function and then execute on client, that might work, but clientside trying to access something from the gamemode just wont work as far as i know.
I would strongly suggest making a class derived from AHUD and doing all of your widget processing there. It’s a class dedicated to handing the Heads up display.
Set your custom class in your game mode.
Then you can get call APlayerController->GetHUD() and cast it to your custom hud and call the adding or removing of widgets etc.