Forum rules - please read before posting.

Error in some scenes 'nullreferenceexception'

Hi, I'm coming back to my work on this after a few months, I've updated, I've reassigned all the 'managers' and some of the scenes work fine.  Some, however, are closing out immediately upon loading or entering from another scene with the following error:
NullReferenceException: Object reference not set to an instance of an object
AC.Char.get_CanPhysicallyRotate () (at Assets/AdventureCreator/Scripts/Character/Char.cs:3736)
AC.Char.get_TransformForward () (at Assets/AdventureCreator/Scripts/Character/Char.cs:3777)
AC.Char.PrepareSpriteChild (Boolean isTopDown, Boolean isUnity2D) (at Assets/AdventureCreator/Scripts/Character/Char.cs:2580)
AC.Player.Initialise () (at Assets/AdventureCreator/Scripts/Character/Player.cs:113)
AC.KickStarter.OnAwake () (at Assets/AdventureCreator/Scripts/Game engine/KickStarter.cs:996)
AC.MultiSceneChecker.Awake () (at Assets/AdventureCreator/Scripts/Game engine/MultiSceneChecker.cs:47)


Comments

  • edited February 2018
    1) Is your player present in the scene file, or spawned at runtime?
    2) Are you relying on multiple player prefabs?
    3) What animation engine are you using for your characters?

    Open up Char.cs, and find line 3736:

    if (animEngine.isSpriteBased && !turn2DCharactersIn3DSpace && motionControl != MotionControl.Manual)

    Immediately above it, insert the following:

    if (animEngine == null) ResetAnimationEngine ();

    Does that resolve the issue?
  • Update: never mind the questions, I've recreated it.  The fix above should fix it, but I'll push an official update out shortly.  Thanks for the post, and apologies for the trouble.
  • That certainly did the trick, I was worried I had really screwed something up there.  I don't know if this is related but a few of my scenes, after updating, had their default 'Navcams' deactivated.  Specifically, 'Game Camera 2D' (Script)' had been unchecked in 'Navcam 1' in at least two separate scenes.  Nothing major of course, initially it was just confusing.

    Thanks for the help, very much appreciated.
  • Just a quick note: I've had the same problem. I reverted to the previous version as I was in a rush, but I'm happy it'll be fixed quickly.

    I couldn't ask for a better support, the AC is pure awesomeness.
  • @NakedCosomnaut: You mean, the component was deactivated in the Inspector?  What about the GameCamera2D prefab itself, in /AdventureCreator/Prefabs/Cameras?  Please post details in a new thread.

    @Martin: It's out now - v1.61.2 fixes the issue.
  • Thanks!
    Your speed is impressive. But so is the quality of entire Adventure Creator, both code and support.
  • edited March 2019

    Hello.
    I got very similar error with AC v. 1.66.8 after upgrade from 1.62.6
    During gameplay when loads the scene where Player already presents I get:

    NullReferenceException: Object reference not set to an instance of an object
    AC.Char.AnimateHeadTurn () (at Assets/AdventureCreator/Scripts/Character/Char.cs:3082)
    AC.Char.SnapHeadMovement () (at Assets/AdventureCreator/Scripts/Character/Char.cs:2954)
    AC.Char.ClearHeadTurnTarget (Boolean isInstant) (at Assets/AdventureCreator/Scripts/Character/Char.cs:2939)
    AC.Player.LoadPlayerData (PlayerData playerData, Boolean justAnimationData) (at Assets/AdventureCreator/Scripts/Character/Player.cs:887)
    AC.SaveSystem.AssignPlayerAnimData (AC.Player player) (at Assets/AdventureCreator/Scripts/Save system/SaveSystem.cs:1433)
    AC.KickStarter.SetLocalPlayerID (AC.Player player) (at Assets/AdventureCreator/Scripts/Game engine/KickStarter.cs:1244)
    AC.KickStarter.AssignLocalPlayer () (at Assets/AdventureCreator/Scripts/Game engine/KickStarter.cs:1340)
    AC.KickStarter.OnAwake () (at Assets/AdventureCreator/Scripts/Game engine/KickStarter.cs:1049)
    AC.MultiSceneChecker.Awake () (at Assets/AdventureCreator/Scripts/Game engine/MultiSceneChecker.cs:46)
    
  • Welcome to the community, @AHPyXA.

    In Char.cs, replace line 3082:

    animEngine.TurnHead (actualHeadAngles);
    

    with:

    GetAnimEngine ().TurnHead (actualHeadAngles);
    

    Does that resolve the issue?

  • Yes. I can confirm this resolve the issue for me.
    Thank you very much, @ChrisIceBox

  • Hi all,

    I believe this is a similar issue, any ideas? Thanks for any help in advance!

    NullReferenceException: Object reference not set to an instance of an object
    AC.AdvGame.GetScreenNavMesh (UnityEngine.Vector3 targetWorldPosition) (at Assets/AdventureCreator/Scripts/Static/AdvGame.cs:1060)
    AC.PlayerStart.SetPlayerStart () (at Assets/AdventureCreator/Scripts/Navigation/PlayerStart.cs:67)
    AC.SceneSettings.FindPlayerStart () (at Assets/AdventureCreator/Scripts/Game engine/SceneSettings.cs:166)
    AC.SceneSettings.OnStart () (at Assets/AdventureCreator/Scripts/Game engine/SceneSettings.cs:130)
    AC.MultiSceneChecker.Start () (at Assets/AdventureCreator/Scripts/Game engine/MultiSceneChecker.cs:72)

    Don

  • It's unrelated. What version of AC/Unity are you using, at what point does the error occur, and what is the result of it showing?

    The stacktrace suggests that your MainCamera is not tagged as "MainCamera" in its Inspector - is this the case?

  • edited April 2019

    Hi Chris,

    Thanks for the help. I started over and added a game camera component, set it to main camera and added the main camera script to it and all is good now.

    Does that essentially restore the maincamera? Or am I supposed to restore the maincamera in a different way?

  • The GameCamera and MainCamera should be separate - don't try to convert one into the other.

    The AC MainCamera prefab can be found in Assets/AdventureCreator/Prefabs/Automatic. It should be placed in your scene for you when organising scene objects in the Scene Manager, but you can drop it in there manually from the prefabs folder as well.

  • I got a related problem only in some scenes for some reason:

    NullReferenceException: Object reference not set to an instance of an object
    AC.SceneChanger.PrepareSceneForExit (System.Boolean isInstant, System.Boolean saveRoomData, System.Boolean doOverlay) (at Assets/AdventureCreator/Scripts/Game engine/SceneChanger.cs:1041)
    AC.SceneChanger.ChangeScene (System.Int32 nextSceneIndex, System.Boolean saveRoomData, System.Boolean forceReload, System.Boolean doOverlay) (at Assets/AdventureCreator/Scripts/Game engine/SceneChanger.cs:253)
    AC.ActionScene.Run () (at Assets/AdventureCreator/Scripts/Actions/ActionScene.cs:127)
    AC.ActionList+d__41.MoveNext () (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:428)
    UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) (at <58a34b0a618d424bb5fc18bb9bcdac20>:0)
    UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)
    AC.ActionList:ProcessAction(Int32) (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:379)
    AC.ActionList:ProcessActionEnd(ActionEnd, Int32, Boolean) (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:580)
    AC.ActionList:EndAction(Action) (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:539)
    AC.d__41:MoveNext() (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:493)
    UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)
    AC.ActionList:ProcessAction(Int32) (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:379)
    AC.ActionList:BeginActionList(Int32, Boolean) (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:346)
    AC.ActionList:Interact(Int32, Boolean) (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:247)
    AC.ActionList:Interact() (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:210)
    AC.SceneSettings:PlayStartCutscene() (at Assets/AdventureCreator/Scripts/Game engine/SceneSettings.cs:332)
    AC.SceneSettings:OnStart() (at Assets/AdventureCreator/Scripts/Game engine/SceneSettings.cs:110)
    AC.SaveSystem:InitAfterLoad() (at Assets/AdventureCreator/Scripts/Save system/SaveSystem.cs:691)
    AC.MultiSceneChecker:Start() (at Assets/AdventureCreator/Scripts/Game engine/MultiSceneChecker.cs:62)

    No idea what to do I'm not really a programmer...

  • What are your AC and Unity versions, and at what point does this message display?

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.