Jump to content

The official unoffical "help a fellow plugin developer" thread


Recommended Posts

On 9/17/2021 at 3:20 PM, se5a said:

but for that I need the exhaust velocity (Isp), and burn rate for the active vessel, how do I get those?

Get a reference to your vessel, then do something like this:
 

// Get ref to your vessel, and subsequnetly a ref to the engine. 
// You probably want to use FindPartModulesImplementing<ModuleEngines>() instead, to get all engines, but for this example
// I'm going with this.
ModuleEngines engine = vessel.FindPartModuleImplementing<ModuleEngines>();
  
// The realIsp value may not be the right one to use. There's several fields with Isp in the name which may be applicable, 
// you'll have to do some testing.
float ISP = engine.realIsp;
  
// You'll have to figure out how to use each propellant individually. This just shows how to get them.
foreach (Propellant prop in engine.propellants)
{
    // iirc the ratio is basically propellant use per second. 
    //There may be other values in the ModuleEngine that have to do with this instead.
	float usagePerSecond = prop.ratio;
}

 

Link to comment
Share on other sites

Awesome, I assume for multiple engines I'm going to want if(engine.staged && !engine.engineShutdown) to get the current stage and active engines?

Is there some documentation somewhere that explicitly states what each of the functions/methods do/return? I'm somewhat disappointed there's not even the normal C# xml trippleslash comments on them.

I realize a lot of this could be figured out by trial and error, but it takes wwwwwaaaay too long to restart ksp to easily figure it out.  (I assume there's no way to hot reload a mod right?)

Link to comment
Share on other sites

2 minutes ago, se5a said:

Is there some documentation somewhere that explicitly states what each of the functions/methods do/return? I'm somewhat disappointed there's not even the normal C# xml trippleslash comments on them.

The official documentation has type signatures but usually not much in the way of explanation:

Link to comment
Share on other sites

You can use KSPFields to display extra data in the existing right click menu. Alternatively you could have a button that brings up a custom UI. I would recommend the former though.

On 9/23/2021 at 6:02 PM, se5a said:

I realize a lot of this could be figured out by trial and error, but it takes wwwwwaaaay too long to restart ksp to easily figure it out.  (I assume there's no way to hot reload a mod right?)

I went ahead and deleted most of the part files from my dev install, that combined with an SSD makes my load time less than a minute.

Link to comment
Share on other sites

I would like to add thrust vectoring to my impulse engines, but can't use ModuleGimbal because of the way I need the engines to work.  I think I have a way to do this, but I need to be able to tell when control input is made.  I assume I could use GetKeyDown() to tell if the pitch, roll, yaw keys are pressed, but I'm not sure that is the best option.

Is there a way to generally tell if a pitch/roll/yaw input has been made regardless of whether it came from the keyboard, mouse, joystick, gamepad, or the SAS?  I know that the FlightCtrlState class has pitch, roll, and yaw attributes, but are these just the current pitch, roll, and yaw angles of the active vessel, or do they hold the current amount of pitch, roll, and yaw input?  I presume it's the former rather than the latter.

Edit:  I realized that the FlightCtrlState class is where I've been getting the main throttle setting and set up a quick test and confirmed that ctrlState.pitch/roll/yaw do give me the values I need for both manual input and SAS control.  So, I self-answered my question.  Thanks to anyone who saw this and was investigating an answer.

Edited by TheShadow1138
found the answer
Link to comment
Share on other sites

  • 3 months later...

I've recompiled the "Kerbin Cup" mod from 2014 for the latest version of KSP to eliminate the unending log spam about an exception due to the defunct KSPUtils.dll file not being found:

S5WyWlC.jpg

Due to the unique circumstances of this mod though, it being an "official" mod created and originally released by SQUAD, I hesitate to start a release thread and provide downloads of it. Could someone with the authority give me the green light, or could someone direct me to the most painless way to get someone with the authority to do so?

Link to comment
Share on other sites

11 hours ago, problemecium said:

Due to the unique circumstances of this mod though, it being an "official" mod created and originally released by SQUAD, I hesitate to start a release thread and provide downloads of it. Could someone with the authority give me the green light, or could someone direct me to the most painless way to get someone with the authority to do so?

I think this part already gives you maximum leeway to do whatever you want with it (including weird stuff that I'm sure you don't want to do such as claiming the original was your own work or using it in a competing commercial product):

On 6/16/2014 at 11:40 PM, SQUAD said:

under a public domain license

Link to comment
Share on other sites

  • 4 months later...
Posted (edited)

I'm currently trying to develop my first mod for KSP as a part of a project at uni. I have no experience in Unity, C# or object oriented programming in general, which makes it quite a challenge. But I knew that when picking the project and it was even kind of the reason to do so. So far I'm learning a lot and enjoy every single success. Just to let you know that I know that I don't know much.... yet. :confused: 

I want to build an ingame code editor. I have it basicly running (quick and dirty, but good enough so far) in the Unity game window when assigning my .cs-scripts directly like most tutorials on YouTube do. According to D'Magic's tutorial on UI creation I have to hook up the UI by importing the .dll which causes some trouble in my case.

As a MRE think of my UI as a panel with a TMPro input field and a button. Pressing the button saves the InputField.text in a .txt-file. Resulting in the following Unity assembly.

using System.IO;
using UnityEngine;
using TMPro;

namespace SimpleEditor.Unity
{
  public class SimpleEditorController
  {
    public TMP_InputField InputField;

    public void SaveInput()
    {
      File.WriteAllText("output.txt", InputField.text);
    }
  }
}

When I try to add the .dll as script to my  get a warning that a GameObject references runtime script in scene file and furthermore, the following error:

Quote

TypeLoadException: Could not load type of field 'Joolyter.Unity.JoolyterController:CodeInputField' (0) due to: Could not resolve type with token 01000011 (from typeref, class/assembly TMPro.TMP_InputField, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null) assembly:Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null type:TMPro.TMP_InputField member:(null) signature:<none>

(Names in error are different due to cope&paste from original error)

I set up my Unity project according to the official PartTools-post. The references in VS are set like D'Magic did in BasicOrbit (I checked his project). Is this an issue of the TMPro versions? To my understanding that shouldn't be the case because the assembly compiles just fine since I added Assembly-CSharp as a reference in VS.

I'm a little lost here and would be very grateful about a small push in the right direction.

 

Edit:

Noob-mistake: I mixed up the references and had to add the TectMeshPro 2017 dll from my unity project folder.  It works now in Unity and i will continue the tutorial(s).

Edited by paulscoletta
Problem solved
Link to comment
Share on other sites

  • 2 weeks later...
Posted (edited)

In the hope that I don't misuse this thread as my rubber duck again I'll ask another question. As stated above im following @DMagic's Tutorial on UI creation. Because TMP (1.0.53 for Unity 2017.3) is integrated into KSP (1.12.3) and Unity (2019.4.18) I am trying to skip creating th UI in Unity Editor with normal text objects and convert them to TMP_Text fields when loading the AssetBundle. But unfortunatly I'm missing somthing since no TMP_Text fields are found in my AssetBundle's prefab when loaded into KSP.

To give you a heads up behind the spoiler is my Unity Scene.

Spoiler

1H0lYaa.jpg

I use the following code to load my prefab into KSP.

Spoiler
using UnityEngine;
using TMPro;

namespace Joolyter
{
    [KSPAddon(KSPAddon.Startup.Instantly, true)]
    public class JoolyterLoader : MonoBehaviour
    {
        public static GameObject EditorPrefab { get; private set; }

        private void Awake()
        {
            string path = "C:/Program Files (x86)/Steam/steamapps/common/Kerbal Space Program CLEAN/GameData/Joolyter/Ressources/";
            AssetBundle prefabs = AssetBundle.LoadFromFile(path + "joolyterassetbundle");
            EditorPrefab = prefabs.LoadAsset("JoolyterEditorPanel") as GameObject;

            if (EditorPrefab != null)
            {
                ProcessFontTextFields(EditorPrefab);
                ProcessFontInputFields(EditorPrefab);
                CheckComponents(EditorPrefab);
            }
        }

        private void ProcessFontTextFields(GameObject prefab)
        {
            TextMeshProUGUI[] texts = prefab.GetComponentsInChildren<TextMeshProUGUI>();
            Debug.Log("[JoolyterLoader.ProcessFontTextFields]: Number of TextFields: " + texts.Length);

            foreach (TextMeshProUGUI text in texts)
            {
                Debug.Log("[JoolyterLoader.ProcessFontTextFields]: " + text.name);
                text.font = UISkinManager.TMPFont;
                text.fontSharedMaterial = Resources.Load("Fonts/Materials/Calibri Dropshadow", typeof(Material)) as Material;
            }
        }

        private void ProcessFontInputFields(GameObject prefab)
        {
            TMP_InputField[] inputs = prefab.GetComponentsInChildren<TMP_InputField>();
            Debug.Log("[JoolyterLoader.ProcessFontInputFields]: Number of InputFields: " + inputs.Length);

            foreach (TMP_InputField input in inputs)
            {
                Debug.Log("[JoolyterLoader.ProcessFontInputFields]: " + input.name);
                input.fontAsset = UISkinManager.TMPFont;
            }
        }

        private void CheckComponents(GameObject prefab)
        {
            Component[] comps = prefab.GetComponentsInChildren<Component>(true);
            Debug.Log("[JoolyterLoader.CheckComponents]: Number of Components: " + comps.Length);

            foreach (Component comp in comps)
            {
                Debug.Log("[JoolyterLoader.CheckComponents]: " + comp.name + " " + comp.GetType());
            }
        }
    }
}

An excerpt of the resulting KSP.log shows that no errors or exceptions are thrown but no TextMeshProUGUI component is found. When I try the same in my Unity assembly and editor game view all components are found using gameObject.GetComponentsInChildren<Type type>().

KSP.log:

Spoiler
[LOG 18:21:17.994] [JoolyterLoader.ProcessFontTextFields]: Number of TextFields: 0
[LOG 18:21:17.994] [JoolyterLoader.ProcessFontInputFields]: Number of InputFields: 0
[LOG 18:21:17.994] [JoolyterLoader.CheckComponents]: Number of Components: 123
[LOG 18:21:17.994] [JoolyterLoader.CheckComponents]: JoolyterEditorPanel UnityEngine.RectTransform
[LOG 18:21:17.994] [JoolyterLoader.CheckComponents]: JoolyterEditorPanel UnityEngine.CanvasRenderer
[LOG 18:21:17.994] [JoolyterLoader.CheckComponents]: JoolyterEditorPanel UnityEngine.UI.Image
[LOG 18:21:17.994] [JoolyterLoader.CheckComponents]: JoolyterEditorPanel Joolyter.Unity.Editor
[LOG 18:21:17.994] [JoolyterLoader.CheckComponents]: TitleBar UnityEngine.RectTransform
[LOG 18:21:17.994] [JoolyterLoader.CheckComponents]: TitleBar UnityEngine.CanvasRenderer
[LOG 18:21:17.994] [JoolyterLoader.CheckComponents]: TitleBar UnityEngine.UI.Image
[LOG 18:21:17.994] [JoolyterLoader.CheckComponents]: Title UnityEngine.RectTransform
[LOG 18:21:17.994] [JoolyterLoader.CheckComponents]: Title UnityEngine.CanvasRenderer
[LOG 18:21:17.994] [JoolyterLoader.CheckComponents]: Title TMPro.TextMeshProUGUI
[LOG 18:21:17.994] [JoolyterLoader.CheckComponents]: Title UnityEngine.UI.ContentSizeFitter
[LOG 18:21:17.994] [JoolyterLoader.CheckComponents]: ExitButton UnityEngine.RectTransform
[LOG 18:21:17.994] [JoolyterLoader.CheckComponents]: ExitButton UnityEngine.CanvasRenderer
[LOG 18:21:17.994] [JoolyterLoader.CheckComponents]: ExitButton UnityEngine.UI.Image
[LOG 18:21:17.994] [JoolyterLoader.CheckComponents]: ExitButton UnityEngine.UI.Button
[LOG 18:21:17.995] [JoolyterLoader.CheckComponents]: XImage UnityEngine.RectTransform
[LOG 18:21:17.995] [JoolyterLoader.CheckComponents]: XImage UnityEngine.CanvasRenderer
[LOG 18:21:17.995] [JoolyterLoader.CheckComponents]: XImage UnityEngine.UI.Image
[LOG 18:21:17.995] [JoolyterLoader.CheckComponents]: Toolbar UnityEngine.RectTransform
[LOG 18:21:17.995] [JoolyterLoader.CheckComponents]: FileMenu UnityEngine.RectTransform
[LOG 18:21:17.995] [JoolyterLoader.CheckComponents]: NewButton UnityEngine.RectTransform
[LOG 18:21:17.995] [JoolyterLoader.CheckComponents]: NewButton UnityEngine.CanvasRenderer
[LOG 18:21:17.995] [JoolyterLoader.CheckComponents]: NewButton UnityEngine.UI.Image
[LOG 18:21:17.995] [JoolyterLoader.CheckComponents]: NewButton UnityEngine.UI.Button
[LOG 18:21:17.995] [JoolyterLoader.CheckComponents]: TextMeshPro Text UnityEngine.RectTransform
[LOG 18:21:17.995] [JoolyterLoader.CheckComponents]: TextMeshPro Text UnityEngine.CanvasRenderer
[LOG 18:21:17.995] [JoolyterLoader.CheckComponents]: TextMeshPro Text TMPro.TextMeshProUGUI
[LOG 18:21:17.995] [JoolyterLoader.CheckComponents]: OpenButton UnityEngine.RectTransform
[LOG 18:21:17.995] [JoolyterLoader.CheckComponents]: OpenButton UnityEngine.CanvasRenderer
[LOG 18:21:17.995] [JoolyterLoader.CheckComponents]: OpenButton UnityEngine.UI.Image
[LOG 18:21:17.995] [JoolyterLoader.CheckComponents]: OpenButton UnityEngine.UI.Button
[LOG 18:21:17.995] [JoolyterLoader.CheckComponents]: TextMeshPro Text UnityEngine.RectTransform
[LOG 18:21:17.995] [JoolyterLoader.CheckComponents]: TextMeshPro Text UnityEngine.CanvasRenderer
[LOG 18:21:17.995] [JoolyterLoader.CheckComponents]: TextMeshPro Text TMPro.TextMeshProUGUI
[LOG 18:21:17.995] [JoolyterLoader.CheckComponents]: SaveButton UnityEngine.RectTransform
[LOG 18:21:17.995] [JoolyterLoader.CheckComponents]: SaveButton UnityEngine.CanvasRenderer
[LOG 18:21:17.995] [JoolyterLoader.CheckComponents]: SaveButton UnityEngine.UI.Image
[LOG 18:21:17.995] [JoolyterLoader.CheckComponents]: SaveButton UnityEngine.UI.Button
[LOG 18:21:17.995] [JoolyterLoader.CheckComponents]: TextMeshPro Text UnityEngine.RectTransform
[LOG 18:21:17.995] [JoolyterLoader.CheckComponents]: TextMeshPro Text UnityEngine.CanvasRenderer
[LOG 18:21:17.995] [JoolyterLoader.CheckComponents]: TextMeshPro Text TMPro.TextMeshProUGUI
[LOG 18:21:17.995] [JoolyterLoader.CheckComponents]: SaveAsButton UnityEngine.RectTransform
[LOG 18:21:17.995] [JoolyterLoader.CheckComponents]: SaveAsButton UnityEngine.CanvasRenderer
[LOG 18:21:17.995] [JoolyterLoader.CheckComponents]: SaveAsButton UnityEngine.UI.Image
[LOG 18:21:17.995] [JoolyterLoader.CheckComponents]: SaveAsButton UnityEngine.UI.Button
[LOG 18:21:17.995] [JoolyterLoader.CheckComponents]: TextMeshPro Text UnityEngine.RectTransform
[LOG 18:21:17.995] [JoolyterLoader.CheckComponents]: TextMeshPro Text UnityEngine.CanvasRenderer
[LOG 18:21:17.995] [JoolyterLoader.CheckComponents]: TextMeshPro Text TMPro.TextMeshProUGUI
[LOG 18:21:17.995] [JoolyterLoader.CheckComponents]: ViewMenu UnityEngine.RectTransform
[LOG 18:21:17.995] [JoolyterLoader.CheckComponents]: ZoomInButton UnityEngine.RectTransform
[LOG 18:21:17.995] [JoolyterLoader.CheckComponents]: ZoomInButton UnityEngine.CanvasRenderer
[LOG 18:21:17.995] [JoolyterLoader.CheckComponents]: ZoomInButton UnityEngine.UI.Image
[LOG 18:21:17.995] [JoolyterLoader.CheckComponents]: ZoomInButton UnityEngine.UI.Button
[LOG 18:21:17.995] [JoolyterLoader.CheckComponents]: TextMeshPro Text UnityEngine.RectTransform
[LOG 18:21:17.995] [JoolyterLoader.CheckComponents]: TextMeshPro Text UnityEngine.CanvasRenderer
[LOG 18:21:17.995] [JoolyterLoader.CheckComponents]: TextMeshPro Text TMPro.TextMeshProUGUI
[LOG 18:21:17.995] [JoolyterLoader.CheckComponents]: ZoomOutButton UnityEngine.RectTransform
[LOG 18:21:17.995] [JoolyterLoader.CheckComponents]: ZoomOutButton UnityEngine.CanvasRenderer
[LOG 18:21:17.995] [JoolyterLoader.CheckComponents]: ZoomOutButton UnityEngine.UI.Image
[LOG 18:21:17.995] [JoolyterLoader.CheckComponents]: ZoomOutButton UnityEngine.UI.Button
[LOG 18:21:17.995] [JoolyterLoader.CheckComponents]: TextMeshPro Text UnityEngine.RectTransform
[LOG 18:21:17.995] [JoolyterLoader.CheckComponents]: TextMeshPro Text UnityEngine.CanvasRenderer
[LOG 18:21:17.995] [JoolyterLoader.CheckComponents]: TextMeshPro Text TMPro.TextMeshProUGUI
[LOG 18:21:17.995] [JoolyterLoader.CheckComponents]: EditorArea UnityEngine.RectTransform
[LOG 18:21:17.995] [JoolyterLoader.CheckComponents]: EditorScrollView UnityEngine.RectTransform
[LOG 18:21:17.995] [JoolyterLoader.CheckComponents]: EditorScrollView UnityEngine.CanvasRenderer
[LOG 18:21:17.995] [JoolyterLoader.CheckComponents]: EditorScrollView UnityEngine.UI.Image
[LOG 18:21:17.995] [JoolyterLoader.CheckComponents]: EditorScrollView UnityEngine.UI.ScrollRect
[LOG 18:21:17.995] [JoolyterLoader.CheckComponents]: Viewport UnityEngine.RectTransform
[LOG 18:21:17.995] [JoolyterLoader.CheckComponents]: Viewport UnityEngine.CanvasRenderer
[LOG 18:21:17.995] [JoolyterLoader.CheckComponents]: Viewport UnityEngine.UI.Image
[LOG 18:21:17.995] [JoolyterLoader.CheckComponents]: Viewport UnityEngine.UI.Mask
[LOG 18:21:17.995] [JoolyterLoader.CheckComponents]: Content UnityEngine.RectTransform
[LOG 18:21:17.995] [JoolyterLoader.CheckComponents]: CodeInputField UnityEngine.RectTransform
[LOG 18:21:17.995] [JoolyterLoader.CheckComponents]: CodeInputField UnityEngine.CanvasRenderer
[LOG 18:21:17.995] [JoolyterLoader.CheckComponents]: CodeInputField UnityEngine.UI.Image
[LOG 18:21:17.995] [JoolyterLoader.CheckComponents]: CodeInputField TMPro.TMP_InputField
[LOG 18:21:17.995] [JoolyterLoader.CheckComponents]: Text Area UnityEngine.RectTransform
[LOG 18:21:17.995] [JoolyterLoader.CheckComponents]: Text Area UnityEngine.UI.RectMask2D
[LOG 18:21:17.995] [JoolyterLoader.CheckComponents]: Placeholder UnityEngine.RectTransform
[LOG 18:21:17.995] [JoolyterLoader.CheckComponents]: Placeholder UnityEngine.CanvasRenderer
[LOG 18:21:17.995] [JoolyterLoader.CheckComponents]: Placeholder TMPro.TextMeshProUGUI
[LOG 18:21:17.995] [JoolyterLoader.CheckComponents]: Text UnityEngine.RectTransform
[LOG 18:21:17.995] [JoolyterLoader.CheckComponents]: Text UnityEngine.CanvasRenderer
[LOG 18:21:17.995] [JoolyterLoader.CheckComponents]: Text TMPro.TextMeshProUGUI
[LOG 18:21:17.995] [JoolyterLoader.CheckComponents]: Scrollbar Horizontal UnityEngine.RectTransform
[LOG 18:21:17.995] [JoolyterLoader.CheckComponents]: Scrollbar Horizontal UnityEngine.CanvasRenderer
[LOG 18:21:17.995] [JoolyterLoader.CheckComponents]: Scrollbar Horizontal UnityEngine.UI.Image
[LOG 18:21:17.996] [JoolyterLoader.CheckComponents]: Scrollbar Horizontal UnityEngine.UI.Scrollbar
[LOG 18:21:17.996] [JoolyterLoader.CheckComponents]: Sliding Area UnityEngine.RectTransform
[LOG 18:21:17.996] [JoolyterLoader.CheckComponents]: Handle UnityEngine.RectTransform
[LOG 18:21:17.996] [JoolyterLoader.CheckComponents]: Handle UnityEngine.CanvasRenderer
[LOG 18:21:17.996] [JoolyterLoader.CheckComponents]: Handle UnityEngine.UI.Image
[LOG 18:21:17.996] [JoolyterLoader.CheckComponents]: LineNumberOutputField UnityEngine.RectTransform
[LOG 18:21:17.996] [JoolyterLoader.CheckComponents]: LineNumberOutputField UnityEngine.CanvasRenderer
[LOG 18:21:17.996] [JoolyterLoader.CheckComponents]: LineNumberOutputField UnityEngine.UI.Image
[LOG 18:21:17.996] [JoolyterLoader.CheckComponents]: LineNumberOutputField TMPro.TMP_InputField
[LOG 18:21:17.996] [JoolyterLoader.CheckComponents]: Text Area UnityEngine.RectTransform
[LOG 18:21:17.996] [JoolyterLoader.CheckComponents]: Text Area UnityEngine.UI.RectMask2D
[LOG 18:21:17.996] [JoolyterLoader.CheckComponents]: Text UnityEngine.RectTransform
[LOG 18:21:17.996] [JoolyterLoader.CheckComponents]: Text UnityEngine.CanvasRenderer
[LOG 18:21:17.996] [JoolyterLoader.CheckComponents]: Text TMPro.TextMeshProUGUI
[LOG 18:21:17.996] [JoolyterLoader.CheckComponents]: Scrollbar Vertical UnityEngine.RectTransform
[LOG 18:21:17.996] [JoolyterLoader.CheckComponents]: Scrollbar Vertical UnityEngine.CanvasRenderer
[LOG 18:21:17.996] [JoolyterLoader.CheckComponents]: Scrollbar Vertical UnityEngine.UI.Image
[LOG 18:21:17.996] [JoolyterLoader.CheckComponents]: Scrollbar Vertical UnityEngine.UI.Scrollbar
[LOG 18:21:17.996] [JoolyterLoader.CheckComponents]: Sliding Area UnityEngine.RectTransform
[LOG 18:21:17.996] [JoolyterLoader.CheckComponents]: Handle UnityEngine.RectTransform
[LOG 18:21:17.996] [JoolyterLoader.CheckComponents]: Handle UnityEngine.CanvasRenderer
[LOG 18:21:17.996] [JoolyterLoader.CheckComponents]: Handle UnityEngine.UI.Image
[LOG 18:21:17.996] [JoolyterLoader.CheckComponents]: InputField UnityEngine.RectTransform
[LOG 18:21:17.996] [JoolyterLoader.CheckComponents]: InputField UnityEngine.CanvasRenderer
[LOG 18:21:17.996] [JoolyterLoader.CheckComponents]: InputField UnityEngine.UI.Image
[LOG 18:21:17.996] [JoolyterLoader.CheckComponents]: InputField UnityEngine.UI.InputField
[LOG 18:21:17.996] [JoolyterLoader.CheckComponents]: Placeholder UnityEngine.RectTransform
[LOG 18:21:17.996] [JoolyterLoader.CheckComponents]: Placeholder UnityEngine.CanvasRenderer
[LOG 18:21:17.996] [JoolyterLoader.CheckComponents]: Placeholder UnityEngine.UI.Text
[LOG 18:21:17.996] [JoolyterLoader.CheckComponents]: Text UnityEngine.RectTransform
[LOG 18:21:17.996] [JoolyterLoader.CheckComponents]: Text UnityEngine.CanvasRenderer
[LOG 18:21:17.996] [JoolyterLoader.CheckComponents]: Text UnityEngine.UI.Text
[LOG 18:21:17.996] [JoolyterLoader.CheckComponents]: Text UnityEngine.RectTransform
[LOG 18:21:17.996] [JoolyterLoader.CheckComponents]: Text UnityEngine.CanvasRenderer
[LOG 18:21:17.996] [JoolyterLoader.CheckComponents]: Text UnityEngine.UI.Text

 

To get this far I have to include "TextMeshPro-2017.3-1.0.56-Runtime.dll" in my GameData folder in order to run the Unity assembly in KSP. Should that be necessary? I set up my references in VS like this:

Spoiler

B0EzSPd.jpg

Is there an issue?

As soon as the UI is supposed to be shown all TMP_Text elements throw a NullReferenceException which isn't that much of a mystery to me if they aren't loaded properly in the first place.

 

I tried but I seem to not being able to figure it out by myself so any effort to help is much appreciated.

Edited by paulscoletta
Try to offer better insight / typos
Link to comment
Share on other sites

  • 3 weeks later...
On 6/7/2022 at 7:54 PM, paulscoletta said:

An excerpt of the resulting KSP.log shows that no errors or exceptions are thrown but no TextMeshProUGUI component is found. When I try the same in my Unity assembly and editor game view all components are found using gameObject.GetComponentsInChildren<Type type>().

[SNIP]

To get this far I have to include "TextMeshPro-2017.3-1.0.56-Runtime.dll" in my GameData folder in order to run the Unity assembly in KSP. Should that be necessary? I set up my references in VS like this:

I feel like I owe you an apology @paulscoletta, for leaving you on read. I think I found the root of your problem 10 days ago but only now got around to writing a post.

What I believe is happening is that there are two human-identical TMPro types at play that are not computer-identical. The KSP devs baked the TMP code into the Assembly-CSharp.dll and so inside of Assembly-CSharp.dll, there is one set of TMP types (TMP_Text, TMP_InputField, etc.). Meanwhile, in the Unity editor, you've been using another set of TMP types from the TextMeshPro-2017... .dll. While these types are identical from a source code and signature perspective, because they're defined in two separate assemblies, they're not the same to the computer. This is why you have needed to add the TextMeshPro DLL to your GameData folder to get your Unity assembly to load in KSP - the TMP types its looking for aren't the ones in Assembly-CSharp.

The same goes for the TMP_Text elements throwing NullRefs - all the font assets they're looking for are font assets defined by the TextMeshPro DLL, and not the font assets loaded by KSP that are the Assembly-CSharp.dll versions.

So how to fix this? That's what I'm working on right now too for the revamp to my Kerbal Wind Tunnel UI...

I managed to get the Unity editor to let me include Assembly-CSharp.dll in my Unity project so that I only need one assembly for my mod. (I feel like I shouldn't bury this tip, but you can make careful use of 'AssemblyDefinition' assets to force Unity not to make its own 'Assembly-CSharp.dll' file and then it doesn't complain about loading KSP's - as long as you also import other .dll files that it needs)

This also meant that I had to remove the TextMeshPro dll so that I didn't have conflicting type definitions. Fine, done. But then all of my TMP elements in my UI refused to show their text because KSP's startup sequence hadn't loaded any fonts. I think the underlying text data is still there, it's just that the font is null. KSP also only bundles the distribution/player methods for TMP, so a lot of the editor functionality was broken.

I've fallen back on the method DMagic mentioned in their tutorial and have replaced all my TMP elements with standard Unity elements and have created a helper type that can change from Unity UI elements to TMP elements. It also acts as a middleman for other script references so I can ask it to change text values or act on input from input fields without having to know in my other scripts whether I'm in Unity UI mode or TMP mode. But this is still in testing.

Hopefully this helps your troubleshooting, and I'd be happy to collaborate on finding clever ways forward. TMP is far superior to pixelated Unity UI text.

Link to comment
Share on other sites

  • 4 weeks later...

Hello ! I'm trying to create objects in the Tracking Station view. My goal is to draw lines using Unity's LineRenderers, but for now I'm struggling just making any game object appear.
I tried adding a sphere to the scene. Here is my code :

[KSPAddon(KSPAddon.Startup.TrackingStation, false)]
public class Example : MonoBehaviour
{
  Dictionary<string, CelestialBody> bodiesByName = new Dictionary<string, CelestialBody>();

  public void Start(){
    List<CelestialBody> bodies = PSystemManager.Instance.localBodies;
    foreach(CelestialBody body in bodies){
      string name = body.GetName();
      bodiesByName.Add(name, body);
    }

    CelestialBody kerbin = bodiesByName["Kerbin"];
    CelestialBody mun = bodiesByName["Mun"];

    Debug.Log("Kerbin: " + kerbin.transform.position);
    Debug.Log("Mun: " + mun.transform.position);
    Debug.Log(kerbin.Radius);

    GameObject obj = GameObject.CreatePrimitive(PrimitiveType.Sphere);
    obj.transform.position = kerbin.transform.position;
    float scale = 4f*(float)kerbin.Radius;
    obj.transform.localScale = new Vector3(scale, scale, scale);
  }

  public void Update()
  {

  }
}

I'm expecting to see a white sphere that has twice the radius of Kerbin and is at the same position as Kerbin (so Kerbin is not visible). But I see nothing, no sphere placed anywhere, all looks as if my code wasn't there. What am I doing wrong ?

My first attempt actually was to place the sphere between Kerbin and Mun (kerbin.transform.position*0.5f + mun.transform.position*0.5f). But when I look at the coordinates of Mun and Kerbin that are displayed in the console, they don't make sense. They have the same y component (which is normal since Mun's orbit is perfectly equatorial), but the x and z components are completely unrelated (positive x for Kerbin, negative x for Mun). Am I missing something ?

 

Thanks for your help !

Link to comment
Share on other sites

The  view in KSP is composed of multiple camera. And some of those camera uses a different scale than the rest of the world. In the tracking station/map view you basically have the ScaledSpace Camera  PlanetariumCamera.Camera  (where you have your planets and orbits) and the galaxy Camera (a small cube with the texture of the galaxy background).  Those cams only displays objects with the proper culling mask. 

So if you want your sphere to show up then the GameObject needs to be assigned to the right Layer. You can find a list here . And you will need to use "Scaled Scenery" for your needs.

And you will have to search the forum about ScaledSpace and WorldSpace to place the item where you actually want them if you want to use orbits or "real" space coordinate.

Edit : set FlightCamera.fetch.cullingMask   to -1 while in the flight view if you want to better understand what is going on. (or set it to ~(1 << LayerMask.NameToLayer("SkySphere")) to hide everything but the galaxy box)

Edited by sarbian
Link to comment
Share on other sites

9 hours ago, sarbian said:

So if you want your sphere to show up then the GameObject needs to be assigned to the right Layer. You can find a list here . And you will need to use "Scaled Scenery" for your needs.

And you will have to search the forum about ScaledSpace and WorldSpace to place the item where you actually want them if you want to use orbits or "real" space coordinate.

Thanks for your response. So here is my attempt after gathering the ideas I got from browsing the forum for ScaledSpace. At least I see something, but it doesn't make any sense (see picture below). The sphere appears very far away and gigantic (which gives a kind of funny apocalyptic view to be honest :D), and the lighting doesn't seem right either considering its position.
The code in the Start() function:

List<CelestialBody> bodies = PSystemManager.Instance.localBodies;
foreach(CelestialBody body in bodies){
	string name = body.GetName();
	bodiesByName.Add(name, body);
}

CelestialBody kerbin = bodiesByName["Kerbin"];
  
GameObject obj = GameObject.CreatePrimitive(PrimitiveType.Sphere);
obj.layer = 10; // Scaled Scenery layer
obj.transform.position = ScaledSpace.LocalToScaledSpace(kerbin.position);
float scale = 4f;
obj.transform.localScale = new Vector3(scale, scale, scale);
obj.transform.parent = ScaledSpace.Instance.transform;

AM-JKLWLHCMNjRWLQN4b_P_f-le-bWJRt3Axc5TO

 

From the documentation, CelestiaBody.position is the position of the body in world coordinates, and ScaledSpace.LocalToScaledSpace() converts a position from world coordinates to the scaled coordinates used in the map and tracking station view. Is there something I'm misunderstanding ?

Link to comment
Share on other sites

I am a bit rusty with all that but I would do

GameObject obj = GameObject.CreatePrimitive(PrimitiveType.Sphere);
obj.layer = 10; // Scaled Scenery layer
float scale = 4f;
obj.transform.localScale = new Vector3(scale, scale, scale);
obj.transform.parent = ScaledSpace.Instance.transform;
obj.transform.localPosition = ScaledSpace.LocalToScaledSpace(kerbin.position);

 

Link to comment
Share on other sites

1 hour ago, sarbian said:

I am a bit rusty with all that but I would do

GameObject obj = GameObject.CreatePrimitive(PrimitiveType.Sphere);
obj.layer = 10; // Scaled Scenery layer
float scale = 4f;
obj.transform.localScale = new Vector3(scale, scale, scale);
obj.transform.parent = ScaledSpace.Instance.transform;
obj.transform.localPosition = ScaledSpace.LocalToScaledSpace(kerbin.position);

 

It gives the same result as in my post. I also tried replacing ScaledSpace.Instance.transform by ScaledSpace.SceneTransform, but again, same result.
One weird thing to note is that although the sphere looks like it's very far away from the solar system, if you align the view with the sun, the sphere is rendered in front of the sun and blocks it partially (picture below):

AM-JKLUoZJGN1K-_WqEiwj-TQlwJR_JKg6LHOsHc

Link to comment
Share on other sites

Try with ScaledSpace.SceneTransform as the parent. If it does not work you will have to wait for someone else to help because I will be away for a few days.

Link to comment
Share on other sites

After trying some stuff and looking at the source code of mods (especially this one https://github.com/JPLRepo/TarsierSpaceTechnology ) I managed to get it somewhat working. It seems to work if you set the parent of the GameObject to one of the (scaled version) bodies GameObjects.

obj = GameObject.CreatePrimitive(PrimitiveType.Sphere);
obj.layer = 10;
float scale = 2f*(float)bodiesByName["Kerbin"].Radius / ScaledSpace.ScaleFactor;
obj.transform.localScale = scale * Vector3.one;
obj.transform.parent = kerbin.scaledBody.transform;
obj.transform.position = ScaledSpace.LocalToScaledSpace((kerbin.position + mun.position)*0.5);

This displays this in the tracking station :

AM-JKLUf2nW9N30Ial4D4-MW3A17uUe-opIoEUqB

 

Howevers, since Kerbin is rotating, and the sphere is attached to Kerbin, it rotates too :

AM-JKLVX_BF2-UMYjVnAh_8uie9CAN3xPSgmpeUQ

 

I also tried using a `baseTransform` as in the mod I linked, but it gives the same results.

If instead I set the parent of the sphere to `ScaledSun.Instance.transform`, now the sphere is rotating around the sun in some elliptic orbit pattern (when time warp at maximum). Why does that happen ?
Morover, the lighting of the sphere becomes non sense if I put it closer to the sun.

Now, if I set the parent of the sphere to `ScaledSpace.SceneTransform` (which is the same as `kerbin.scaledBody.transform.parent`), I'm back to the same results as in my previous post.

What am I missing ?

Link to comment
Share on other sites

Anyone here profficient with LineRenderer?

I have been recently updating Solar Sail Navigator to be compatible with the latest version of Persistent Thrust Extended, and would like to get it working in planetary SOI's. The only problem is, while the lines are rendered in the right place initially, it seems like the planet's orbit 'leaves behind' the lines. I've tried many approaches to parenting the line renderer to whichever planet is the current reference body, but get strange behavior when I do so.

Any thoughts?

Link to comment
Share on other sites

@nubeees I'm not sure if I understood correctly but I guess what you mean is that the lines appear first where you placed them (in the map view), but then seem to drift away from the planet. Am I right ?

If that's the case, I think I encountered the same problem. I solved it by constantly updating (recalculating) the positions of the lines' points at each frame in Update or LateUpdate. And I don't think you even need to attach the line object to any other object if you do that, except the scaledScene.

Edited by Krafpy
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...