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"

Why does my Gamemode classes reset to default on editor startup?

Hey, i'm having some trouble with my gamemode at the moment. I have a gamemode class in C++ in which i set the default pawn class and the player controller class. But each time i start the editor the two classes that i set are reset to the default value. But they have that small yellow arrow to reset the value back to the classes that were set using C++.

The gamemode blueprint. alt text

The world settings

alt text

Maps and Modes, project settings alt text

And the code in the gamemode class.

 AHomeInvasionGameMode::AHomeInvasionGameMode(const FObjectInitializer& ObjectInitializer)
     : Super(ObjectInitializer)
 {
     // set default pawn class to our Blueprinted character
     static ConstructorHelpers::FClassFinder<APawn> PlayerPawnBPClass(TEXT("/Game/Blueprints/Player/BP_FPSCharacter"));
     if (PlayerPawnBPClass.Class != NULL)
     {
         DefaultPawnClass = PlayerPawnBPClass.Class;
     }
 
     // Set default player controller class to our blueprint
     static ConstructorHelpers::FClassFinder<APlayerController> ControllerBPClass(TEXT("/Game/Blueprints/General/BP_PlayerController"));
     if (ControllerBPClass.Class != NULL)
     {
         PlayerControllerClass = ControllerBPClass.Class;
     }
 }
Product Version: UE 4.8
Tags:
more ▼

asked Aug 05 '15 at 09:51 AM in Using UE4

avatar image

Solicio
200 52 53 63

avatar image Xenome Aug 05 '15 at 10:21 AM

Just out of curiosity, what happens if you skip the NULL-checks?

(comments are locked)
10|2000 characters needed characters left

1 answer: sort voted first

To find out where the values are being set use a memory breakpoint - this is how you do it in visual studio:

  1. put a normal breakpoint in the constructor

  2. when paused there get the address of a variable that is being set (for instance put &PlayerControllerClass in a watch window).

  3. take the hex value for that variable address and...

  4. ... open the breakpoints window, then select "New Data Breakpoint" from the dropdown in the top left

  5. enter the hex address

  6. continue debugging (f5). The program should pause again when something edits the value of that variable

My guess is that the blueprint defaults are overriding the C++ defaults somewhere in the actor spawning code and you should move the assignment to some other function (InitGame perhaps?).

more ▼

answered Aug 05 '15 at 06:10 PM

avatar image

theonecalledtom
1.2k 58 61 265

avatar image Solicio Aug 06 '15 at 09:44 AM

Hey, i did some testing following your instructions but was unable to find where the values were set back to the defaults. I tried moving the code to InitGame but it just crashes when the game is started.

I also tried moving the order which the values are set (switching place of the pawn and controller code so that the controller is first) which for some reason fixes it for the player controller and it is always set after starting the editor, the pawn class is still set to the default value.

avatar image theonecalledtom Aug 06 '15 at 04:53 PM

So the data breakpoints didn't fire at all? Are the values seen to change in the debugger between initialization and runtime? If so I'd expect the data breakpoint to tell you where - while they can have some caveats on some architectures I've found them pretty easy to use on PC in Unreal. If not then that's probably a clue about something!

Swapping the order doesn't changing behavior doesn't make sense to me, but I don't really know the initialization process very well, just having delved to solve my own problems.

Nor does moving the code to InitGame causing crashes, unless you moved the construction helper which only seems to work during construction :)

 //IN CONSTRUCTOR
      static ConstructorHelpers::FClassFinder<APawn> PlayerPawnBPClass(TEXT("/Game/Blueprints/Player/BP_FPSCharacter"));
      if (PlayerPawnBPClass.Class != NULL)
      {
          TmpVariableNotAUPROPERTYPerhapsAStatiCDefaultPawnClass = PlayerPawnBPClass.Class;
      }

 //IN INITGAME
 DefaultPawnClass = TmpVariableNotAUPROPERTYPerhapsAStatiCDefaultPawnClass;


 
 



(comments are locked)
10|2000 characters needed characters left
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