Jump to content

CommNetNetwork.Instance is null


Recommended Posts

I let the following picture show the problem:

l9lYOxu.png

The background is I am building a case on one stock CommNet bug to submit to KSP's bug tracker. I was minimizing the number of reproduction steps but I encounter this null problem. I don't understand why CommNetNetwork.Instance is null while KSP's visual network is operating properly.

Spoiler

using System;
using System.Collections.Generic;
using System.Linq;

using UnityEngine;
using CommNet;

namespace CommLinkBug
{
    [KSPAddon(KSPAddon.Startup.Flight, false)]
    public class Simple : MonoBehaviour
    {
        public void Start()
        {
            if (CommNetNetwork.Instance == null)
                return;

            List<CommLink> allCommLinks = CommNetNetwork.Instance.CommNet.Links;
            for (int i = 0; i < allCommLinks.Count(); i++)
            {
                CommLink thisLink = allCommLinks.ElementAt(i);
                double strength = thisLink.signalStrength;
                HopType type = thisLink.hopType;
            }
        }
    }
}

 

 

Full stock KSP 1.2.1604 with this bug-demonstration mod (Just CommLink.dll, CommLink.dll.mdb, CommLink.pdb)

Do you have any idea on this null nature?

(Checking if it is very project name (CommLink) that confuses KSP.... None, never mind)

Edited by TaxiService
Link to comment
Share on other sites

4 hours ago, sarbian said:

Because it is not yet ready when Start run. You should use the  OnNetworkInitialized  GameEvent to know when things are ready

Oh I see, it is my first time to learn about this GameEvents feature. Thanks for pointing me to the correct direction.

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...