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"

How to extend functions in GameMode class?

Hi! I'm little confused about extending functions. I want to spawn my pawn in nav mesh location so I need to extend RestartPlayer function in MyGameMode. I've put in this in MyGameMode.h

 virtual void RestartPlayer(class AController* NewPlayer) override;

but when I put declartion in cpp file then I'll get all UE_LOG's with error. Also there is "use of undefined type 'APlayerState'" build error. So it dosen't look like this function use GameMode variables. I'm still thinking in US way so I'm surprised that this isn't working :)

I've just started with c++ so can someone show me the way how to do it? Thanks.

Product Version: UE 4.8
Tags:
more ▼

asked Aug 14 '15 at 04:59 PM in C++ Programming

avatar image

Waw K.
70 14 26 33

avatar image Timoses Aug 14 '15 at 06:42 PM

First thing you should do: Solely have the overwritten function RestartPlayer as an empty function, add a breakpoint and see if it enters the function.

Did you set your custom GameMode class to be used in the editor's project settings?

avatar image Waw K. Aug 14 '15 at 07:06 PM

I'm not sure how to use breakpoints. I've added it in VS and started instance in Debug Game Editor but nothing happens. I've also added UELOG but theres is no this message in Output. My GameMode is set correctly. So I understand that I didn't missed something obvious and all what I should do to extend function is that what I've made?

EDIT: Maybe RestartPlayer function isn't triggered anyway but generaly my problem is why compiler can't find reference from parent function?

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

2 answers: sort voted first

If you haven't dont so yet, read this: https://docs.unrealengine.com/latest/INT/Programming/Development/index.html .

Breakpoints are points that you can set at lines of code to tell the debugger to prior to executing this line. Look here and scroll to "Debugging breakpoint" http://www.dotnetperls.com/debugging .

If you say you've done everything correct then I'm not sure where to help : ).

What UE_LOG channel are you using? Since not all are active. I usually use

 UE_LOG(LogEngine, Error,  TEXT("bla bla"));

when I just want to quickly check.

more ▼

answered Aug 16 '15 at 11:15 AM

avatar image

Timoses
91 14 14 22

avatar image Waw K. Aug 16 '15 at 06:07 PM

Thanks for tips. I always wonder what's going on with breakpoints.

I use logs very often so i'm surprised that it's not working. This is my error log from VS builder after copy RestartPlayer function from AGameMode class to AMyGamemode.

For Example this line

 UE_LOG(LogGameMode, Verbose, TEXT("RestartPlayer %s"), (NewPlayer && NewPlayer->PlayerState) ? *NewPlayer->PlayerState->PlayerName : TEXT("Unknown"));

 generates this error


     1>C:\UE4\ProtoBall\Source\ProtoBall\ProtoBallGameMode.cpp(31): error C2653: 'FLogCategoryLogGameMode' : is not a class or namespace name
     1>C:\UE4\ProtoBall\Source\ProtoBall\ProtoBallGameMode.cpp(31): error C2065: 'CompileTimeVerbosity' : undeclared identifier
     1>C:\UE4\ProtoBall\Source\ProtoBall\ProtoBallGameMode.cpp(31): error C2065: 'LogGameMode' : undeclared identifier
     1>C:\UE4\ProtoBall\Source\ProtoBall\ProtoBallGameMode.cpp(31): error C2228: left of '.IsSuppressed' must have class/struct/union
     1>          type is 'unknown-type'
     1>C:\UE4\ProtoBall\Source\ProtoBall\ProtoBallGameMode.cpp(31): error C2228: left of '.GetCategoryName' must have class/struct/union
     1>          type is 'unknown-type'
     1>C:\UE4\ProtoBall\Source\ProtoBall\ProtoBallGameMode.cpp(31): error C2027: use of undefined type 'APlayerState'
     1>          C:\Program Files\Epic Games\4.8\Engine\Source\Runtime\Engine\Classes\GameFramework/Pawn.h(13) : see declaration of 'APlayerState'
     1>C:\UE4\ProtoBall\Source\ProtoBall\ProtoBallGameMode.cpp(31): error C2227: left of '->PlayerName' must point to class/struct/union/generic type
     1>C:\UE4\ProtoBall\Source\ProtoBall\ProtoBallGameMode.cpp(31): error C2660: 'FMsg::Logf_Internal' : function does not take 4 arguments

avatar image Timoses Aug 16 '15 at 10:07 PM

Do you have TeamPlayerController.h added in your header file?

To always be sure the right headers are included create a c++ class from the editor: https://docs.unrealengine.com/latest/INT/Programming/Development/ManagingGameCode/CppClassWizard/index.html

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

For the specific issue of the UE_LOG errors:

  1. Open up MyGameMode.cpp

  2. Scroll to the top of the file, right after the #include directives but before any functions.

  3. Add the text: DEFINE_LOG_CATEGORY_STATIC(LogGameMode, Log, All);

This should resolve the compilation issues, at least those related to logging. This line is copied directly from GameMode.cpp in the engine.

For actually inheriting RestartPlayer, you'll probably want to start with something like this:

 void MyGameMode::RestartPlayer(AController* NewPlayer)
 {
     if (NewPlayer == NULL || NewPlayer->IsPendingKillPending())
     {
         return;
     }
 
     if (NewPlayer->PlayerState && NewPlayer->PlayerState->bOnlySpectator)
     {
         UE_LOG(LogGameMode, Verbose, TEXT("RestartPlayer tried to restart a spectator-only player!"));
         return;
     }
 
     Super::RestartPlayer(NewPlayer);
 
     //Your code here.
 }

The Super:: line is important, as that will execute the existing code in the engine for RestartPlayer. Without that, you'd need to handle getting a StartSpot and possessing a new pawn yourself.

more ▼

answered Oct 10 '15 at 04:11 PM

avatar image

dstreb
46 14 16 20

(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