tomf

Exception with custom making history node

Recommended Posts

I'm attempting to make another custom node for Making History, this time an action to change the focussed vessel. This one fires and changes the focus but seems to be causing an error in the MH code and preventing the next node from firing. Can anyone (probably @SQUAD) tell me what is wrong?

The code for the node

Spoiler

class ActionSwitchFocus : ActionVessel
    {

        public override IEnumerator Fire()
        {
            Debug.Log("Action switch focus is being called");
            Vessel v = FlightGlobals.ActiveVessel;

            bool swit = FlightGlobals.SetActiveVessel(vessel);
            Debug.Log("Switch vessel has finished with " + swit);
            //return base.Fire();
            return Enumerable.Empty<int>().GetEnumerator();
        }
    }

 

 

And the Logs

Spoiler

[HighLogic]: =========================== Scene Change : From FLIGHT to FLIGHT =====================
 
(Filename: C:/buildslave/unity/build/artifacts/generated/common/runtime/DebugBindings.gen.cpp Line: 51)

Switch vessel has finished with True
 
(Filename: C:/buildslave/unity/build/artifacts/generated/common/runtime/DebugBindings.gen.cpp Line: 51)

NullReferenceException
  at (wrapper managed-to-native) UnityEngine.MonoBehaviour:StartCoroutine_Auto_Internal (System.Collections.IEnumerator)
  at UnityEngine.MonoBehaviour.StartCoroutine (IEnumerator routine) [0x00000] in <filename unknown>:0 
  at Expansions.Missions.MENode.ActivateNode (Boolean Loading) [0x00000] in <filename unknown>:0 
  at Expansions.Missions.Mission.SwitchActiveNodes (Expansions.Missions.MENode newNode) [0x00000] in <filename unknown>:0 
  at Expansions.Missions.Mission.UpdateMission () [0x00000] in <filename unknown>:0 
  at Expansions.Missions.Runtime.MissionSystem.UpdateMissions () [0x00000] in <filename unknown>:0 
  at Expansions.Missions.Runtime.MissionSystem.FixedUpdate () [0x00000] in <filename unknown>:0 

 

 

Share this post


Link to post
Share on other sites

I'm not very experienced on MH mods but the Fire() method seems like a coroutine so instead of returning:

return Enumerable.Empty<int>().GetEnumerator();

I would just do:

return 0 

or other parameter that fills your needs.


+Info about coroutines on unity: 
http://www.unitygeek.com/coroutines-in-unity3d/

Edited by Dagger
  • Like 1

Share this post


Link to post
Share on other sites

If it s a coroutine the proper way is "yield return null;"

Share this post


Link to post
Share on other sites

Yup, that got that exception. Still doesn't work though but there is one less exception in the logs. Now I get

NullReferenceException
  at (wrapper managed-to-native) UnityEngine.Transform:INTERNAL_get_position (UnityEngine.Vector3&)
  at UnityEngine.Transform.get_position () [0x00000] in <filename unknown>:0
  at FlightGlobals.getFoR (FoRModes mode, UnityEngine.Transform referenceTransform, .Orbit orbit, .CelestialBody body) [0x00000] in <filename unknown>:0
  at FlightGlobals.GetFoR (FoRModes mode) [0x00000] in <filename unknown>:0
  at FlightCamera+<Startup>c__Iterator0.MoveNext () [0x00000] in <filename unknown>:0
  at UnityEngine.SetupCoroutine.InvokeMoveNext (IEnumerator enumerator, IntPtr returnValueAddress) [0x00000] in <filename unknown>:0
UnityEngine.MonoBehaviour:StartCoroutine_Auto_Internal(IEnumerator)
UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)
FlightCamera:OnLevelLoaded(GameScenes)
FlightCamera:OnSceneLoaded(Scene, LoadSceneMode)
UnityEngine.SceneManagement.SceneManager:Internal_SceneLoaded(Scene, LoadSceneMode)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now