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"

Creating a Controller in GameState fails

Hi there,

I've got a custom class that derives from GameState. I have a function to advance the game to the next "phase", which should spawn a new controller and switch the player to this controller.

When I try and create a new controller via the NewObject function, the game instantly crashes and this is printed to the output:

 Fatal error: [File:D:\BuildFarm\buildmachine_++depot+UE4-Releases+4.6\Engine\Source\Runtime\CoreUObject\Private\Templates\Casts.cpp] [Line: 11] 
 Cast of Class /Script/FantasyStrategy.PlayerUnitController to Level failed
 UE4Editor.exe has triggered a breakpoint.

And the code in question...

     auto instance = (UOlusiaGameInstance*)GetGameInstance();
 
     APlayerUnitController* newController = NewObject<APlayerUnitController>(APlayerUnitController::StaticClass());
     instance->GetLocalPlayerByIndex(0)->SwitchController(newController);

Currently a little rough around the edges as I have been attempting to get some sort of solution.

Is there any reason I cannot instantiate a new controller? I have tried in my GameMode derivative too, with the same error.

Product Version: Not Selected
Tags:
more ▼

asked Feb 13 '15 at 09:06 PM in C++ Programming

avatar image

Mesothere
78 8 20 24

(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