x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

[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

Product Version: Not Selected
Tags:
more ▼

asked Mar 11 '14 at 02:33 AM in C++ Programming

avatar image

ue4-archive ♦♦ STAFF
49.9k 3665 1991 9117

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

2 answers: sort voted first

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 :D

more ▼

answered Mar 11 '14 at 02:33 AM

avatar image

ue4-archive ♦♦ STAFF
49.9k 3665 1991 9117

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

Dear Lim,

 YourProjectClasses.h

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

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


"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

:)

Rama

more ▼

answered Mar 11 '14 at 02:33 AM

avatar image

ue4-archive ♦♦ STAFF
49.9k 3665 1991 9117

avatar image ue4-archive ♦♦ STAFF Mar 11 '14 at 02:33 AM

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 :)

avatar image ue4-archive ♦♦ STAFF Mar 11 '14 at 02:33 AM

"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

avatar image ue4-archive ♦♦ STAFF Mar 11 '14 at 02:33 AM

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);
     }
 }



avatar image ue4-archive ♦♦ STAFF Mar 11 '14 at 02:33 AM

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"
avatar image ue4-archive ♦♦ STAFF Mar 11 '14 at 02:33 AM

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:

alt text

topd.jpg (166.9 kB)
(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question