Forum rules - please read before posting.

Engine: Restart game problem

edited April 2014 in Engine development
I hate to keep bringing up these issues I'm finding, but it looks like the Engine: End game action in which the Restart Game command is used does not work properly.

I'm testing my game, and I have a death menu in which Restart Game is an option, and it calls a menu actionlist in which the only action which is run is the Engine: End Game action with the Restart Game command called to restart the game at scene 0. 

Scene 0, which is just a title screen, loads correctly, but as soon as I try to move to scene 1, in which the player character should be present, the game freezes. The error message is as follows: 

NullReferenceException: Object reference not set to an instance of an object
AC.SceneChanger.ChangeScene (Int32 sceneNumber, Boolean saveRoomData) (at Assets/AdventureCreator/Scripts/Game engine/SceneChanger.cs:30)
ActionScene.Run () (at Assets/AdventureCreator/Scripts/Actions/ActionScene.cs:41)
AC.ActionList+<RunAction>c__Iterator1.MoveNext () (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:148)
UnityEngine.MonoBehaviour:StartCoroutine(String, Object)
AC.ActionList:ProcessAction(Int32) (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:128)
AC.<RunAction>c__Iterator1:MoveNext() (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:177)
UnityEngine.MonoBehaviour:StartCoroutine(String, Object)
AC.ActionList:ProcessAction(Int32) (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:128)
AC.<RunAction>c__Iterator1:MoveNext() (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:177)
UnityEngine.MonoBehaviour:StartCoroutine(String, Object)
AC.ActionList:ProcessAction(Int32) (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:128)
AC.<RunAction>c__Iterator1:MoveNext() (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:177)
UnityEngine.MonoBehaviour:StartCoroutine(String, Object)
AC.ActionList:ProcessAction(Int32) (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:128)
AC.<RunAction>c__Iterator1:MoveNext() (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:177)
UnityEngine.MonoBehaviour:StartCoroutine(String, Object)
AC.ActionList:ProcessAction(Int32) (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:128)
AC.ActionList:BeginActionList(Int32) (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:106)
AC.ActionList:Interact() (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:72)
RuntimeActionList:Play(MenuActionList, Menu) (at Assets/AdventureCreator/Scripts/ActionList/RuntimeActionList.cs:65)
PlayerMenus:CheckClick(Menu, MenuElement, Int32, Int32) (at Assets/AdventureCreator/Scripts/Controls/PlayerMenus.cs:783)
PlayerMenus:OnGUI() (at Assets/AdventureCreator/Scripts/Controls/PlayerMenus.cs:332)


I've noticed that upon restarting the game, the player prefab is NOT found at all in scene 0. It looks like it is not generated at all when restarting the game. Presumably, changing the player's scene is impossible if there is no player prefab present. 

Therefore I assume this is a bug. Has anyone else noticed this problem? Thanks!

Comments

  • Please don't apologise for your bug reporting!  Issues such as this are my top priority, and reporting them benefits everyone.

    Does your game involve multiple player prefabs, or just the one?
  • Just one player, and he is correctly listed in the character settings. Player switching is not allowed.
  • I've tested this and can't recreate the issue.  I'm assuming that your scene 0, while a title screen, still has the GameEngine prefab present?  You should always have the player prefab in your scene, even if it's hidden.  Was this the cause?
  • Weird, this is one of the few problems that I can consistently recreate. 

    Scene 0 does have the GameEngine prefab, yes. But it is not generating the player prefab. And I checked restarting to a different scene, and the same thing happens. Scene 1 is a normal scene in which the player moves around and interacts, but when restarting to scene 1, the player prefab is not present, and the scene runs as it should but without the player present. He can even interact with some things, but there is no prefab present in the hierarchy and clearly none visible. 

    Just for your reference, the player prefab has the movable, highlight, hotspot and remember visibility scripts attached to it, just in case one of these might be causing a problem. The visibility is not the issue, because as I've mentioned, the player isn't just invisible on screen, but also not present in the hierarchy. 
  • Shouldn't affect it, but thanks for the let-know.  Could be a problem with using a possible decrepit Monobehaviour function.  The Kickstater script (attached to the GameEngine) is tasked with creating the Player prefab if it can't find one.

    Inside that script, try changing line 78 from:

    if (!GameObject
    .FindGameObjectWithTag (Tags.player))

    to:

    if
     (GameObject.FindWithTag (Tags.player) == null)
  • Thanks, but that did not seem to work. The player prefab is still not being created when restarting the game. Is there any more information you think I should give you? Any other ideas?
  • No promises, but if you PM me your project I can take a look at it for you - since we're at the same point with your slowdown issue too.
  • What exactly should I send over? My whole assets folder with managers?
  • As little as you can to demonstrate the problem.
  • edited May 2014
    I guess I don't really know how to narrow the problem down, so it will have to be the entire assets folder. I'll send you a download link to the zipped assets folder when it finishes uploading.
  • Chris!

    I am running into similar problems using this action. 
    I keep my 2 players prefabs in an asset folder (declared in the manager, but not present in the scene). Player nr 1 is loaded by default and put in the game. All works fine.

    When calling the Engine -> End Game -> Reset Game action in a menu button, I redirect to the same scene. AC then crashes on this:

    NullReferenceException: Object reference not set to an instance of an object
    AC.RuntimeInventory.GetItemsOnStart () (at Assets/AdventureCreator/Scripts/Inventory/RuntimeInventory.cs:152)
    AC.RuntimeInventory.Start () (at Assets/AdventureCreator/Scripts/Inventory/RuntimeInventory.cs:48)
    AC.ActionEndGame.Run () (at Assets/AdventureCreator/Scripts/Actions/ActionEndGame.cs:70)
    AC.ActionList+<RunAction>c__Iterator1.MoveNext () (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:199)
    UnityEngine.MonoBehaviour:StartCoroutine(String, Object)
    AC.ActionList:ProcessAction(Int32) (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:165)
    AC.ActionList:ProcessActionEnd(ActionEnd, Int32) (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:306)
    AC.ActionList:EndAction(Action) (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:256)
    AC.<RunAction>c__Iterator1:MoveNext() (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:235)
    UnityEngine.MonoBehaviour:StartCoroutine(String, Object)
    AC.ActionList:ProcessAction(Int32) (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:165)
    AC.ActionList:BeginActionList(Int32, Boolean) (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:143)
    AC.ActionList:Interact(Int32, Boolean) (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:105)

    I have tried having the player 1 prefab in the scene instead of in the asset folder, but it doesnt matter. 

  • I will look into it.  Does it work if the player prefab is present in the scene before the game runs?
  • I will look into it.  Does it work if the player prefab is present in the scene before the game runs?
  • Nope it doesnt. That's what's so weird. The player is in the scene, but still null :/ 
  • What I do now to dodge the problem, when the "reset level" button is pressed:

    KickStarter.sceneChanger.ChangeScene ("", Application.loadedLevel, false);  //reload the same level
    KickStarter.runtimeInventory.Start(); //reset the player's inventory items.

    This probably isnt the best way to handle this, but it works for my purposes now. 
  • OK - if that works at least as a temporary measure, then great.  But I will certainly look into this for the next release.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.