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"

[C++]Could someone tell me how to make a custom game state

This line of code doesn't work (it compiles but "MainGameState" is NULL)

 AMainGameState* const MainGameState = (GetWorld() != NULL) ? GetWorld()->GetGameState<AMainGameState>() : NULL;

Also I set the GameStateClass to my custom game state class in my gamemodes c-tor:

 ASLOPE01GameModeBase::ASLOPE01GameModeBase()
 {
     GameStateClass = AMainGameState::StaticClass();
 }
 

I don't really understand how to use the gamemode and gamestate classes and to make my own custom children classes from them.

Product Version: UE 4.20
Tags:
more ▼

asked Nov 05 '18 at 07:00 PM in C++ Programming

avatar image

BALKAN BANDIT
12 1 2 5

avatar image Shadowriver Nov 05 '18 at 09:43 PM

There possibility that gamestate is null pointer at that point, here do you call that first snippet?

avatar image BALKAN BANDIT Nov 06 '18 at 06:14 PM

How should it be done correctly? Yes the first snippet is called in a constructor of an actor

avatar image Tobiw Nov 06 '18 at 06:30 PM

you've set up your game state correctly, it's just null at the moment of the actor's construction becouse actors placed on level get constructed very early. Try to access it in the actor's BeginPlay() instead.

avatar image BALKAN BANDIT Nov 07 '18 at 11:41 AM

Isn't there a way to do it in the constructor because I do this in the base class constructor so when I inherit from it I can take some info out of the gamestate and put it in all the derived classes

avatar image Tobiw Nov 07 '18 at 06:07 PM

you can do that same thing in BeginPlay() as well. When you override the BeginPlay method in dervied classes you call the Super::BeginPlay() method and if you cached all of that needed info in variables you can just access them then.

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

0 answers: sort voted first
Be the first one to answer this question
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