How do you get a variable from another C++ class?

Hey everyone. I’m working on a simple bowling game and I had a variable set up within my Gamemode’s .h file which tells when the ball has been thrown. I then wanted to get that variable from my gamemode and then pass it to my bowling pin class. The main issue I have is that I don’t know how to get the variable from my gamemode and pass it to my Pin class for it to read off of. Any advice?

In your bowling pin class’ cpp, remember to include:

#include "YourGameMode.h"

Then, in your bowling pin class you can do the following:

// Get World
UWorld* world = GetWorld();

if (world)
{
	// Game mode 
	AYourGameMode* gameMode = Cast<AYourGameMode>(world->GetAuthGameMode());
	if (gameMode)
	{
		float myGameModeFloat = gameMode->someFloatVariable;
            ...do stuff
	}
}

Ah I see. So I had to cast to my gamemode in order to access the variables. Thanks a lot! Also if you’re Canadian, have a great Thanksgiving!

Advance Happy thanksgiving to you all.