Jump to content

Need some help with VesselRenameDialog


Recommended Posts

I'd like to be able to use the VesselRenameDialog class to get name and vesseltype for things which are not (yet) vessels.  But I'm having a problem, am hoping that someone can give me a clue.

I'm calling the following from a part module which has a right-click action, all that is done during the right click is below:

This code will bring up the dialog for the current vessel:

KSP.UI.Screens.VesselRenameDialog.Spawn(FlightGlobals.ActiveVessel, null, null, true, VesselType.Probe);

So I figured that I'd just create a new vessel. add a Part with a ModuleCommand to it and use this new vessel, but the following code,gets a null reference error:

Vessel v = new Vessel ();
v.vesselType = FlightGlobals.ActiveVessel.vesselType;
// this line causes a null reference error   v.name = FlightGlobals.ActiveVessel.name;
v.vesselName = FlightGlobals.ActiveVessel.vesselName;
Part p = new Part ();
// This line causes a null reference error    p.name = "test1";
p.CrewCapacity = 0;
p.mass = 0;
p.vesselType = VesselType.Probe;
p.AddModule("ModuleCommand");

v.Parts.Add (p);
KSP.UI.Screens.VesselRenameDialog.Spawn(v, onAccept, onDismiss, true, VesselType.Probe);

Here is the error:

NullReferenceException
  at (wrapper managed-to-native) UnityEngine.Component:get_gameObject ()
  at Part.AddModule (System.String moduleName) [0x00000] in <filename unknown>:0
  at Lib.Stager.ActivateEvent () [0x00000] in <filename unknown>:0
  at BaseEvent.Invoke () [0x00000] in <filename unknown>:0
  at UIPartActionButton.OnClick () [0x00000] in <filename unknown>:0
  at UnityEngine.Events.InvokableCall.Invoke (System.Object[] args) [0x00000] in <filename unknown>:0
  at UnityEngine.Events.InvokableCallList.Invoke (System.Object[] parameters) [0x00000] in <filename unknown>:0
  at UnityEngine.Events.UnityEventBase.Invoke (System.Object[] parameters) [0x00000] in <filename unknown>:0
  at UnityEngine.Events.UnityEvent.Invoke () [0x00000] in <filename unknown>:0
  at UnityEngine.UI.Button.Press () [0x00000] in <filename unknown>:0
  at UnityEngine.UI.Button.OnPointerClick (UnityEngine.EventSystems.PointerEventData eventData) [0x00000] in <filename unknown>:0
  at UnityEngine.EventSystems.ExecuteEvents.Execute (IPointerClickHandler handler, UnityEngine.EventSystems.BaseEventData eventData) [0x00000] in <filename unknown>:0
  at UnityEngine.EventSystems.ExecuteEvents.Execute[IPointerClickHandler] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.EventFunction`1 functor) [0x00000] in <filename unknown>:0
UnityEngine.Debug:Internal_LogException(Exception, Object)
UnityEngine.Debug:LogException(Exception)
UnityEngine.EventSystems.ExecuteEvents:Execute(GameObject, BaseEventData, EventFunction`1)
UnityEngine.EventSystems.StandaloneInputModule:ProcessMousePress(MouseButtonEventData)
UnityEngine.EventSystems.StandaloneInputModule:ProcessMouseEvent(Int32)
UnityEngine.EventSystems.StandaloneInputModule:ProcessMouseEvent()
UnityEngine.EventSystems.StandaloneInputModule:Process()
UnityEngine.EventSystems.EventSystem:Update()

Thanks in advance

Edited by linuxgurugamer
Link to comment
Share on other sites

This likely isn't working because Part and Vessel are MonoBehaviours, and that using the constructor definitely is not the correct way to spawn a new MonoBehaviour, and if the stuff in the unity functions are critical, they will fail. You're also assuring yourself that the Update and FixedUpdate methods for both objects you spawned won't ever be called.

tl;dr: don't use the constructor if you want to spawn a MonoBehaviour object and want it to behave like a MonoBehaviour object.

Edited by stupid_chris
Link to comment
Share on other sites

1 hour ago, stupid_chris said:

This likely isn't working because Part and Vessel are MonoBehaviours, and that using the constructor definitely is not the correct way to spawn a new MonoBehaviour, and if the stuff in the unity functions are critical, they will fail. You're also assuring yourself that the Update and FixedUpdate methods for both objects you spawned won't ever be called.

tl;dr: don't use the constructor if you want to spawn a MonoBehaviour object and want it to behave like a MonoBehaviour object.

Turned out that I was doing it wrong.  I've totally rewritten it, but now I need to use the icons which are in the VesselRenameDialog dialog.    Any ideas?

Link to comment
Share on other sites

12 hours ago, linuxgurugamer said:

Turned out that I was doing it wrong.  I've totally rewritten it, but now I need to use the icons which are in the VesselRenameDialog dialog.    Any ideas?

Do you solely need the icons are you need the entire dialog?

Link to comment
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
×
×
  • Create New...