Trying to get a variable to identify

What I want to do is I want a door to open after someone enters a password into a widget I set up with blueprint. I created a C++ class to open the door which works and I am now trying to set up a if statement for it to open when a variable I created changes.

To make a variable I can access in both blueprint a c++ I followed this guide and my variable I created in gamemodebase c++ component now shows up in blueprint: A new, community-hosted Unreal Engine Wiki - Announcements - Epic Developer Community Forums

Now I am trying to introduce my variable into other .cpp files specifically the one that opens my door but the problem is its not Identifying. My suspicions are that I am missing #include.

Here is header file for my game mode:

And here is my .cpp c++ component for the door;

][3]

And here is the variable working in blueprint am trying to have it so when this is set c++ class for my door will take note of it and open the door according to my if statement.

You see the get and cast you do in your BP code to set the variable. You’ll have to make the equivalent get and cast to get the variable in c++.

You need to do something like this:

ACemeteryFPSGameModeBase* CemeteryGameMode = Cast(UGamePlayStatics:GetGameMode(GetWorld()));

if(CemeteryGameMode->GateKey > 1)
OpenGate();

I gave it a shot but “Cast” has a error “no instance overloaded function” & “UGamePlayStatics:” is coming up as “Identifier is undefined”.

I was thinking I was missing a include for UGamePlayStatics so I included the following in my .cpp:

#include “Runtime/Engine/Classes/Kismet/GameplayStatics.h”

But it still appears as undefined. I am assuming I am missing some includes.

OK I fixed the issue with UGamePlaystatics by changing the capital P to a small p to get UGameplayStatics.

However the issue with cast is still present and Get World now has the following error:
Uworld *UActorComponent::GetWorld() const
argument of type “UWorld *” is incompatible with parameter type “const UObject”

Hi,

Apologize for that, the example listed in my comment is incorrect. Initially I thought I wrote it incorrectly but it appears the forums here doesn’t like a full cast < > example. Put your ACemeteryFPSGameModeBase between those symbols in the example below.

Use Cast<>(UGameplayStatistics::GetGameMode(GetWorld()));

Thanks it greatly appreciated, It works now. The door now opens after a user interacts with my blueprint made widget in my game.