Jump to content

Part with custom Part Module not showing up


Recommended Posts

I created a custom plugin from scratch that does beamed power for the stock game and I made two part modules- 'WirelessSource' and 'WirelessReceiverDirectional'. The 'WirelessSource' part module works perfectly, but the receiver module when I attach it to a part, the part doesn't show up in the editor. The debug menu says the models/textures were loaded, but the part itself doesn't. It does show up when I remove the receiver module from it. I narrowed down the problem to be between the 'CheckifOccluded()' function and the method under 'FixedUpdate()'. Which part of my code is not done correctly? I tried to figure this out and have spent 8 hours on it, with no success.

I am testing this on a nearly stock install, with the exception of a few models from other mods that I attach the part modules to. The game version is 1.10.1

Source code:

https://drive.google.com/drive/folders/1jNXrAVssbB1dR6YRVU0vc8XGWsyPT0WZ?usp=sharing

Log File:

https://drive.google.com/file/d/1oLgxGZNb7XrKI-Utnemf8bqDLFf2dcHy/view?usp=sharing

Any help would be appreciated!

Edited by Aniruddh
Added Log file
Link to comment
Share on other sites

20 minutes ago, Aniruddh said:

Uploaded the Player.log, I can't find the KSP.log anywhere, is the Player.log sufficient?

It is but it s harder to read. On Windows you should have a KSP.log in your game install dir.

Anyway you have this exception in the loading screen :

NullReferenceException: Object reference not set to an instance of an object
  at FlightGlobals.get_ActiveVessel () [0x00005] in <c1858a3f77504bd1aaa946fdccf84670>:0 
  at BeamedPowerStandalone.WirelessReceiverDirectional..ctor () [0x00021] in <ab0ab7a1d4244ac5a41f0cb5aba6e5ba>:0 
UnityEngine.GameObject:Internal_AddComponentWithType(Type)
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)
UnityEngine.MonoBehaviour:StartCoroutineManaged2(IEnumerator)
UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)
<CompileAll>d__13:MoveNext()
UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)
UnityEngine.MonoBehaviour:StartCoroutineManaged2(IEnumerator)
UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)
PartLoader:StartLoad()
<LoadSystems>d__11:MoveNext()
UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)

This is related to this line in your code :

// get if receiver is occluded from source by a celestial body
public Vector3d dest = FlightGlobals.ActiveVessel.GetWorldPos3D();

First : the active vessel is not static and is position is even less static. You can set it as the member of you class and expect it to reflect the value change over time.

Second : Do not initialize value with calls to KSP or Unity methods like that. Do it in a Awake, Start or Update/FixedUpdate (if it changes)

Third : Parts module are actually loaded in the loading screen. Do not expect your part to be part of a vessel to be active every time your module is. Check for null ans such

Fourth : Read your log. Search for "Exception"

Link to comment
Share on other sites

2 hours ago, sarbian said:

First : the active vessel is not static and is position is even less static. You can set it as the member of you class and expect it to reflect the value change over time.

Second : Do not initialize value with calls to KSP or Unity methods like that. Do it in a Awake, Start or Update/FixedUpdate (if it changes)

Third : Parts module are actually loaded in the loading screen. Do not expect your part to be part of a vessel to be active every time your module is. Check for null ans such

Fourth : Read your log. Search for "Exception"

All four of those points are correct. My code is rather badly written and is kind of crude. These changes implemented, now the part does load up.Thanks for the help! :D 

Link to comment
Share on other sites

I'm running into an issue, same plugin as above, with this part of the code:

public void OnLoad()
{
	if (CorrectVesselList.Count > 0)
	{
		excessList.Clear();
		constantList.Clear();
		CorrectVesselList.Clear();
	}
	for (int x = 0; x < FlightGlobals.Vessels.Count; x++)
	{
		for (int y = 0; y < FlightGlobals.Vessels[x].Parts.Count; y++)
		{
			if (FlightGlobals.Vessels[x].Parts[y].Modules.Contains<WirelessSource>() == true)
			{
				CorrectVesselList.Add(FlightGlobals.Vessels[x]);
				double excess1 = (double)FlightGlobals.Vessels[x].Parts[y].Modules.GetModule<WirelessSource>().Fields.GetValue("excess");
				double constant1 = (double)FlightGlobals.Vessels[x].Parts[y].Modules.GetModule<WirelessSource>().Fields.GetValue("constant");
				excessList.Add(excess1);
				constantList.Add(constant1);
				break;
			}
		}
	}
}

It basically gets all vessels in the current save file that have a part that has the WirelessSource part module. For some reason the CorrectVessel List has no elements in it, and any debugging I try to do returns nothing.

EDIT: Stupid me is trying to cast an object to double, never do this, I instead used Convert.ToDouble (object Obj), and that worked!!!

Edited by Aniruddh
Link to comment
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...