Jump to content

KSP 1.8 plugin update modder questions thread


Recommended Posts

Before posting to this thread, first make sure you've read this post:

I decided to start this thread for any modders with a question about something that worked in KSP 1.7.3 but broke in KSP 1.8 and they don't know how to fix it.  I'm starting it because I have my own question about that, but I figure it would be useful to have all these simple questions collected into one thread.

This is just for questions of the form, "Previously I did this in 1.7.3 and it worked.  In KSP 1.8 it doesn't anymore and I'm not sure what the new way is supposed to be to do it.  What should I replace this code with instead?"  Because there is an official SQUAD post about this, but it's locked, I'm asking people to make sure they've read that one first in case their question is already answered (see link at the top).  This thread is just for things not covered in that post.

Link to post
Share on other sites

EDIT: The following question appears to be moot now.  I found the answer, I think.  See next post for explanation.

 

Here is my first question to start the thread:

PartModule.Fields.TryGetFieldUIControl went away

When Breaking Ground came out, TriggerAU helped me with a problem in kOS, giving the advice that I should use this method when accessing the fields on PAW's for the servo partmodules of BreakingGround:

bool PartModule.Fields.TryGetFieldUIControl(string name, out UI_Control control)

This was a relatively new method I hadn't seen before KSP 1.7.x.  But now In KSP 1.8, it looks like this method doesn't exist anymore, or maybe I need to include another new DLL reference or using statement to make it work.

As of KSP 1.8, It now gives this error when compiling:

"Error    CS1061    'BaseFieldList' does not contain a definition for 'TryGetFieldUIControl' and no extension method 'TryGetFieldUIControl' accepting a first argument of type 'BaseFieldList' could be found (are you missing a using directive or an assembly reference?)    kOS    C:\Users\Steve\Documents\GitHub\KOS-1\src\kOS\Suffixed\PartModuleField\PartModuleFields.cs"

For reference, this is the snippet of kOS's code that it is complaining on:

            // Using TryGetFieldUIControl() to obtain the control that goes with this
            // field is from advice from TriggerAU, who gave that advice in
            // a forum post when I described the problems we were having with the servo
            // parts in Breaking Ground DLC.  (There is some kind of work being done here
            // that seems to allow one field's ranges to override another's as the servo
            // parts need to do.  This is work which doesn't seem to happen if you look at
            // the KSPField's control ranges directly):
            UI_Control control;
            if (!partModule.Fields.TryGetFieldUIControl(field.name, out control)) // <----- Worked in KSP 1.7.x, not in KSP 1.8
            {
                throw new KOSInvalidFieldValueException("Field appears to have no UI control attached so kOS refuses to let a script change it.");
            }

If this call went away or got renamed, what should I replace it with?

Edited by Steven Mading
answer found - A full wipe and re-install fixed it and got newer DLL files for KSP.
Link to post
Share on other sites

Okay it seems something went wrong when I copied over the dll's to the project, and I got older versions of the dlls from KSP 1.6, not the KSP 1.8 version.  That's why the method was missing.  I wiped KSP from steam entirely and redownloaded, then copied the DLLs over to the Visual Studio project folder and THEN it compiled.  I don't know what I did but it was something on my end, clearly.  It's resolved now.

Link to post
Share on other sites
32 minutes ago, FreeThinker said:

THanks, I think I should learn how to use the Unity Search engine at https://docs.unity3d.com/ScriptReference/AnimationState.html

I also had to include UnityEngine.IMGuiModule

 

Yup. And the IMGui one is listed in the modders notes. Linked in the OP.

i also added the animation one to the modders notes.

Link to post
Share on other sites
3 minutes ago, JPLRepo said:

Yup. And the IMGui one is listed in the modders notes. Linked in the OP.

i also added the animation one to the modders notes.

Using Unity Search engine, I managed to find all missing references, which was quite a lot. Finally I can compile all my mods. Now pray they are not broken somehow at run time :0.0:

Edited by FreeThinker
Link to post
Share on other sites

Regarding Unity references, the easy solution is to edit your *.csproj file and use a wildcard search instead of specific references :

<ItemGroup> 
  <Reference Include="Path\To\The\Dlls\UnityEngine*.dll">
    <Private>False</Private>
  </Reference>
</ItemGroup>

 

Link to post
Share on other sites

Can we get a more specific description of the .Net version than just "4.x"? Because I don't know what is safe, I am only using 4.0, not 4.5.  If I could use 4.5 it might be a good idea to do so, but I don't know so I'm avoiding it for now.

Link to post
Share on other sites

Here's one I just tripped over:

PartLoader appears to be instantiating PartModules during loading:

[LOG 13:14:02.326] PartLoader: Compiling Part 'Squad/Parts/Utility/dockingPort/dockingPort/dockingPort2'
[EXC 13:14:02.337] ArgumentNullException: Value cannot be null.
Parameter name: shader
	UnityEngine.Material..ctor (UnityEngine.Shader shader) (at <5aeafee3fea24f37abd1315553f2cfa6>:0)
	AvionicsSystems.MASCamera..cctor () (at <6048b14068c14d96bb3951cfc97dbda9>:0)
	Rethrow as TypeInitializationException: The type initializer for 'AvionicsSystems.MASCamera' threw an exception.
	UnityEngine.GameObject:AddComponent(Type)
	Part:AddModule(String, Boolean)
	Part:AddModule(ConfigNode, Boolean)
	PartLoader:ParsePart(UrlConfig, ConfigNode)
	<CompileParts>d__56:MoveNext()
	UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)
[EXC 13:14:02.338] NullReferenceException: Object reference not set to an instance of an object
	PartModule.Awake () (at <5b6ca6486e0b47a1bce39cde5a91b986>:0)
	UnityEngine.GameObject:AddComponent(Type)
	Part:AddModule(String, Boolean)
	Part:AddModule(ConfigNode, Boolean)
	PartLoader:ParsePart(UrlConfig, ConfigNode)
	<CompileParts>d__56:MoveNext()
	UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)
[ERR 13:14:02.338] PartLoader: Encountered exception during compilation. System.NullReferenceException: Object reference not set to an instance of an object
  at PartModule.ApplyUpgradeNode (System.Collections.Generic.List`1[T] appliedUps, ConfigNode node, System.Boolean doLoad) [0x00029] in <5b6ca6486e0b47a1bce39cde5a91b986>:0 
  at PartModule.Load (ConfigNode node) [0x000f9] in <5b6ca6486e0b47a1bce39cde5a91b986>:0 
  at Part.AddModule (ConfigNode node, System.Boolean forceAwake) [0x0006f] in <5b6ca6486e0b47a1bce39cde5a91b986>:0 
  at PartLoader.ParsePart (UrlDir+UrlConfig urlConfig, ConfigNode node) [0x00e3f] in <5b6ca6486e0b47a1bce39cde5a91b986>:0 
  at PartLoader+<CompileParts>d__56.MoveNext () [0x005cd] in <5b6ca6486e0b47a1bce39cde5a91b986>:0 

[ERR 13:14:02.338] PartCompiler: Cannot compile part

... but MAS doesn't load asset bundles until we reach the main menu (after the LOADING phase), so of course the shader is going to be null.  And, even better, the other module that MAS adds to the docking ports spams NREs during FixedUpdate throughout the rest of the loading cycle (because it assumes it's only going to exist in editor or flight scenes).  The NREs stop at some time around the transition to MAINMENU.  I guess I need to check against the Loading scene on top of the other ones.

EDIT: Actually, it's less obvious what's going on - the  MASCamera module that's throwing an exception is checking HighLogic.LoadedScene at Start() to prevent launching outside of editor and flight, and it doesn't have an explicit constructor, so I don't understand what there's an AvionicsSystems.MASCamera constructor in the call stack.

EDIT 2: NVM - I've got a shader initialized in-line

private static readonly Material fovRendererMaterial = new Material(Shader.Find("Particles/Additive"));

that needs updated.  Maybe it's time for me to stop playing with C# and return to C++.  At least I understand C++ idiosyncrasies. :)

Edited by MOARdV
Link to post
Share on other sites
19 minutes ago, MOARdV said:

Here's one I just tripped over:

PartLoader appears to be instantiating PartModules during loading:

[LOG 13:14:02.326] PartLoader: Compiling Part 'Squad/Parts/Utility/dockingPort/dockingPort/dockingPort2'
[EXC 13:14:02.337] ArgumentNullException: Value cannot be null.
Parameter name: shader
	UnityEngine.Material..ctor (UnityEngine.Shader shader) (at <5aeafee3fea24f37abd1315553f2cfa6>:0)
	AvionicsSystems.MASCamera..cctor () (at <6048b14068c14d96bb3951cfc97dbda9>:0)
	Rethrow as TypeInitializationException: The type initializer for 'AvionicsSystems.MASCamera' threw an exception.
	UnityEngine.GameObject:AddComponent(Type)
	Part:AddModule(String, Boolean)
	Part:AddModule(ConfigNode, Boolean)
	PartLoader:ParsePart(UrlConfig, ConfigNode)
	<CompileParts>d__56:MoveNext()
	UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)
[EXC 13:14:02.338] NullReferenceException: Object reference not set to an instance of an object
	PartModule.Awake () (at <5b6ca6486e0b47a1bce39cde5a91b986>:0)
	UnityEngine.GameObject:AddComponent(Type)
	Part:AddModule(String, Boolean)
	Part:AddModule(ConfigNode, Boolean)
	PartLoader:ParsePart(UrlConfig, ConfigNode)
	<CompileParts>d__56:MoveNext()
	UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)
[ERR 13:14:02.338] PartLoader: Encountered exception during compilation. System.NullReferenceException: Object reference not set to an instance of an object
  at PartModule.ApplyUpgradeNode (System.Collections.Generic.List`1[T] appliedUps, ConfigNode node, System.Boolean doLoad) [0x00029] in <5b6ca6486e0b47a1bce39cde5a91b986>:0 
  at PartModule.Load (ConfigNode node) [0x000f9] in <5b6ca6486e0b47a1bce39cde5a91b986>:0 
  at Part.AddModule (ConfigNode node, System.Boolean forceAwake) [0x0006f] in <5b6ca6486e0b47a1bce39cde5a91b986>:0 
  at PartLoader.ParsePart (UrlDir+UrlConfig urlConfig, ConfigNode node) [0x00e3f] in <5b6ca6486e0b47a1bce39cde5a91b986>:0 
  at PartLoader+<CompileParts>d__56.MoveNext () [0x005cd] in <5b6ca6486e0b47a1bce39cde5a91b986>:0 

[ERR 13:14:02.338] PartCompiler: Cannot compile part

... but MAS doesn't load asset bundles until we reach the main menu (after the LOADING phase), so of course the shader is going to be null.  And, even better, the other module that MAS adds to the docking ports spams NREs during FixedUpdate throughout the rest of the loading cycle (because it assumes it's only going to exist in editor or flight scenes).  The NREs stop at some time around the transition to MAINMENU.  I guess I need to check against the Loading scene on top of the other ones.

EDIT: Actually, it's less obvious what's going on - the  MASCamera module that's throwing an exception is checking HighLogic.LoadedScene at Start() to prevent launching outside of editor and flight, and it doesn't have an explicit constructor, so I don't understand what there's an AvionicsSystems.MASCamera constructor in the call stack.

EDIT 2: NVM - I've got a shader initialized in-line

private static readonly Material fovRendererMaterial = new Material(Shader.Find("Particles/Additive"));

that needs updated.  Maybe it's time for me to stop playing with C# and return to C++.  At least I understand C++ idiosyncrasies. :)

Partloader has always instantiated on loading. 
also there’s a lot of Unity calls that are not allowed in constructors. Like your static material there. Better to define it only as null and set it in Awake.

1 hour ago, Steven Mading said:

Can we get a more specific description of the .Net version than just "4.x"? Because I don't know what is safe, I am only using 4.0, not 4.5.  If I could use 4.5 it might be a good idea to do so, but I don't know so I'm avoiding it for now.

4.x is safe. 4.5 is safe.

Link to post
Share on other sites

Is there something about the 1.8 Part Tools that is preventing it from loading the KSPAssetCompiler.dll? I keep running into this error:

Error: Could not load signature of KSPFontAsset:.ctor due to: Could not load file or assembly 'TextMeshPro-2017.1-1.0.56-Runtime, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. assembly:TextMeshPro-2017.1-1.0.56-Runtime, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null type:<unknown type> member:(null) signature:<none>

This is on a new project, with Unity 2019.2.2f1, and the newest version of Part Tools from here.

It seems like it's running into a problem trying to read from the old version of the TextmeshPro plugin. I also tried removing the built in TMPro package, but that has no effect.

This prevents the KSPedia functions from working in the Unity editor, and would prevent anyone from using the KSP asset bundler function.

Link to post
Share on other sites
12 minutes ago, DMagic said:

Is there something about the 1.8 Part Tools that is preventing it from loading the KSPAssetCompiler.dll? I keep running into this error:

Error: Could not load signature of KSPFontAsset:.ctor due to: Could not load file or assembly 'TextMeshPro-2017.1-1.0.56-Runtime, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. assembly:TextMeshPro-2017.1-1.0.56-Runtime, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null type:<unknown type> member:(null) signature:<none>

This is on a new project, with Unity 2019.2.2f1, and the newest version of Part Tools from here.

It seems like it's running into a problem trying to read from the old version of the TextmeshPro plugin. I also tried removing the built in TMPro package, but that has no effect.

This prevents the KSPedia functions from working in the Unity editor, and would prevent anyone from using the KSP asset bundler function.

Yup. Think there might be some instructions missing.

Remove the built-in TMPro with Unity. And reinstall the old free version used in previous release into your Unity project.

Link to post
Share on other sites

I have a very simple script for auto landing  that is now giving me an error that says, "undefined variable name 'verticalspeed'"

Here's the line that breaks (and I assume all other lines that check verticalspeed)

until verticalspeed>=0

Like I said, this used to work perfectly.  I don't know enough about programming in KOS to program around this.

Link to post
Share on other sites
3 hours ago, Matt Stryker said:

I have a very simple script for auto landing  that is now giving me an error that says, "undefined variable name 'verticalspeed'"

Here's the line that breaks (and I assume all other lines that check verticalspeed)

until verticalspeed>=0

Like I said, this used to work perfectly.  I don't know enough about programming in KOS to program around this.

You appear to be asking a question as a user of the kOS mod, which isn't what this thread is for.  This thread is for people *developing* mods, not using mods.

I put the reply to your post over here instead:


 

Link to post
Share on other sites
On 10/18/2019 at 12:37 PM, Steven Mading said:

Can we get a more specific description of the .Net version than just "4.x"? Because I don't know what is safe, I am only using 4.0, not 4.5.  If I could use 4.5 it might be a good idea to do so, but I don't know so I'm avoiding it for now.

https://docs.microsoft.com/en-us/dotnet/standard/net-standard

https://docs.microsoft.com/en-us/dotnet/standard/frameworks

https://docs.unity3d.com/2019.2/Documentation/Manual/dotnetProfileSupport.html

https://www.mono-project.com/docs/about-mono/compatibility/

 

Unless you have a specific reason to use .NET Framework 4.x, Unity recommends using .NET Standard 2.0; the reason being that Mono supports everything in .NET Standard, but only a sub-set of .NET Framework (and Unity's version of Mono is more unclear because it is an in-house compile). As for which _can_ you use: .NET Standard is fully version-additive, so any of the Framework versions from 4.5 on is fine: newer versions will give you more features that were added later if you need them.

 

There is a sub-note on the net-standard link above: "While NuGet considers .NET Framework 4.6.1 as supporting .NET Standard 1.5 through 2.0, there are several issues with consuming .NET Standard libraries that were built for those versions from .NET Framework 4.6.1 projects. For .NET Framework projects that need to use such libraries, we recommend that you upgrade the project to target .NET Framework 4.7.2 or higher." I'm unsure if this would also affect mono or not.

 

As a note, Microsoft has discontinued all support for 4, 4.5, and 4.5.1 (including no security updates); so I'd recommend not targeting them for any project you do out of habit; though from KSP's perspective, it doesn't matter.

As another note, .NET Framework has been feature end-of-life since April this year with the release of 4.8, which is the last version. From this point on, it will just receive security updates and such. I saw that the compatibility list for Mono does not yet list 4.8, so I would probably avoid targeting it until it does, just in case you use something new.

 

[Edit]

In layman's terms:

- Unity 2019.2 supports everything in .NET Standard 2.0 (and earlier).
- Unity 2019.2 supports some of .NET Framework 4.x, but not everything.
- As long as you don't use things in .NET 4.x that Unity doesn't support, there is no issue.

Edited by Electrocutor
Link to post
Share on other sites
19 minutes ago, Electrocutor said:

As another note, .NET Framework has been end-of-life since April this year with the release of 4.8, which is the last version. I saw that the compatibility list for Mono does not yet list 4.8, so I would probably avoid targeting it until it does.

No. As I explained on the post below, .NET 4.8 BEGUN its life cycle on April this year. You misunderstood the information.

EDIT: Apparently, it's a misunderstanding on the meaning of "End of Life". I think the guy is meaning "End of Development of new Features" . So, yeah - Microsoft is betting high on NET Core. But the Framework still have a huge time ahead on support, and it will be a lot of time until we see it really dead.

I think you need to read this link: https://support.microsoft.com/en-us/lifecycle/search/548

Edited by Lisias
EDIT link to image
Link to post
Share on other sites

I'm getting a new error in 1.8

Uploading Crash Report
MissingMethodException: Default constructor not found for type kerbal_impact.ImpactContract
  at System.RuntimeType.CreateInstanceMono (System.Boolean nonPublic) [0x0007b] in <ad04dee02e7e4a85a1299c7ee81c79f6>:0

ImpactContract is an abstract class and isn't supposed to be instantiated at all. This worked in previous versions but now seems to be blowing up the whole contract system.

Is there a simpler workaround than simply not using the abstract class?

Link to post
Share on other sites
This thread is quite old. Please consider starting a new thread rather than reviving this one.

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.

×
×
  • Create New...