CommonGame Plugin

Hi Devs,
In my project i implemented CommonGame plugin to use UI Layout system, in my c++ class this condition return null so can not get RootLayout:
This is snippet code:
if (UPrimaryGameLayout* RootLayout = Policy->GetRootLayout(CastChecked(LocalPlayer)))
{
const ESlateVisibility DesiredVisibility = bShouldShowUI ? ESlateVisibility::SelfHitTestInvisible : ESlateVisibility::Collapsed;
if (DesiredVisibility != RootLayout->GetVisibility())
{
RootLayout->SetVisibility(DesiredVisibility);

}

}
help me to fix
thanks

You need to create a subsclass in C++ deriving from GameUIManagerSubsystem.

You also need to create a GameUIPolicy-derived blueprint, in which you will list which PrimaryGameLayout to use.

Then, in your DefaultGame.ini (config file), you need to create a reference to that UI policy blueprint, for the property
UPROPERTY(config, EditAnywhere)
TSoftClassPtr<UGameUIPolicy> DefaultUIPolicyClass;
found in UGameUIManagerSubsystem.

Like this, (from lyra’s DefaultGame.ini):

[/Script/LyraGame.LyraUIManagerSubsystem]
DefaultUIPolicyClass=/Game/UI/B_LyraUIPolicy.B_LyraUIPolicy_C

so usually it will vary depending on your package name.

[/Script/PACKAGE_NAME.UI_MANAGER_SUBSYSTEM_NAME]
DefaultUIPolicyClass=/Game/UI_POLICY_BP_PATH.UI_POLICY_BP_NAME_C

Also make sure all you’re using the classes from CommonGame (GameInstance, LocalPlayer, PC) or nothing will work :sunny:

You can check this website for more info: https://zhuanlan.zhihu.com/p/598803136

thanks so much, in my project i implemented all assets that your recommended above and setup inside .ini file, but the RootLayout still return null so it does not get any stacks inside W_OverallHUDLayout to active

I forgot to mention you also need to use UCommonGameViewportClient. You can assign it in the project settings.

1 Like

thanks so much, rely on your note i fixed this error, before i got an error so i changed the parent class CommonGameInstance to GameInstance. Althought this is fixxed but all game features are not working now so hero can not move and do anything. But i think that i can check and fix them again.
thanks so much again.
Truc

1 Like

thanks so much, rely on your note i fixed this error, before i got an error so i changed the parent class CommonGameInstance to GameInstance.