[Question] StrategyGameClasses.h - How to make something similar?

Hello,

I’m trying to replicate the way Epic does when getting linking headers to cpp.

In the StrategyGame sample, some cpp will only include the main header class only which is StrategyGame.h and is still able to get data from other classes

In the StrategyGame.h, I notice that there is a #include "StrategyGameClasses.h"which i assume that it contains/store all the headers in StrategyGame.h

However, i cannot seem to find the StrategyGameClasses.h in the solution explorer. Is it some kind of C++ technique or a header file that is created when the game starts?

Thanks

Hello Rama,

I tried it again on a new project like you suggested and it worked now. Could be a typo that made the error on my other project.

Thanks for helping me out :smiley:

Dear Lim,

YourProjectClasses.h

is auto generated by UE4 and should never be manually edited by you :slight_smile:

One time when I opened MyProjectClasses.h it actually said what I just wrote above in the header comment :slight_smile:


“some cpp will only include the main header class only which is StrategyGame.h”

In my project, every single .cpp includes only the main project .h as you are saying above, apparently there is some change in motion surrounding this,

but that is what I include in every .cpp

:slight_smile:

Rama

Hello Rama,

Thanks for answering. I’m just curious as to how Epic can inherit the data from other classes when they only include the main header file. Cause when i just put my main header class, the functions inherits stuff from other classes will have an error saying: name followed by::must be a class or namespace name.

Unless I’m missing something or some steps that enable one to do so that allows you to only include mainproject.h in your .cpp

Thanks :slight_smile:

“the functions inherits stuff from other classes will have an error saying: name followed by::must be a class or namespace name.”

Can you post a full code sample of .h and .cpp of what your error is referring to?

Are you saying you are using the namespace of other classes in your .cpp file, besides the class of the .cpp itself?

Rama

Hello Rama, so here’s a spectatorpawn class, its very similar with the StrategyGame sample. so lets say i remove the #include RTS_SpectatorPawnMovement.h then there will be an error in URTS_SpectatorPawnMovement section

// Copyright 1998-2013 Epic Games, Inc. All Rights Reserved.

#include "RTS_Real.h"
#include "RTS_RealSpectatorPawn.h"
#include "RTS_RealPlayerController.h"
#include "RTS_SpectatorPawnMovement.h"


ARTS_RealSpectatorPawn::ARTS_RealSpectatorPawn(const class FPostConstructInitializeProperties& PCIP)
	: Super(PCIP.SetDefaultSubobjectClass(Super::MovementComponentName))
{
	bAddDefaultMovementBindings = false;
}

void ARTS_RealSpectatorPawn::CalcCamera(float DeltaTime, FMinimalViewInfo& OutResult)
{
	if (ARTS_RealPlayerController* PC = Cast(GetController()))
	{
		PC->CalcCamera(DeltaTime, OutResult);
	}
	else
	{
		Super::CalcCamera(DeltaTime, OutResult);
	}
}

void ARTS_RealSpectatorPawn::SetupPlayerInputComponent(UInputComponent* InputComponent)
{
	check(InputComponent);

	BIND_AXIS(InputComponent, "MoveForward", &ARTS_RealSpectatorPawn::MoveForward);
	BIND_AXIS(InputComponent, "MoveRight", &ARTS_RealSpectatorPawn::MoveRight);
}


void ARTS_RealSpectatorPawn::MoveForward(float Val)
{
	ARTS_RealPlayerController* PC = Cast(GetController());

	if (PC && Val != 0.f)
	{
		const FRotationMatrix R(PC->PlayerCamera->GetCameraRotation());
		const FVector WorldSpaceAccel = R.GetScaledAxis( EAxis::Z ) * 100;     //Z instead of X

		// transform to world space and add it
		AddMovementInput(WorldSpaceAccel, Val);
	}
}

void ARTS_RealSpectatorPawn::MoveRight(float Val)
{
	ARTS_RealPlayerController* PC = Cast(GetController());
	if (PC && Val != 0.f)
	{
		const FRotationMatrix R(PC->PlayerCamera->GetCameraRotation());
		const FVector WorldSpaceAccel = R.GetScaledAxis( EAxis::Y ) * 100;

	// transform to world space and add it
		AddMovementInput(WorldSpaceAccel, Val);
	}
}

And here is the main header. Do i need to include all the other classes header file here? And if i do so, do declare only this main header file in the other classes/cpp. Thanks

// Copyright 1998-2013 Epic Games, Inc. All Rights Reserved.

#pragma once

#include "Engine.h"
#include "EngineKismetLibraryClasses.h"
#include "EngineUserInterfaceClasses.h"
#include "EngineDecalClasses.h"
#include "SoundDefinitions.h"

I am confused as to how you ended up with your current header setup.

What project template did you start your project from?

I can follow along better if I know that

I’d recommend starting with code top down based on what your goals seem to be: