Jump to content

The official unoffical "help a fellow plugin developer" thread


Recommended Posts

9 hours ago, Krafpy said:

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

Yes, sorry if my phrasing was poor. I was hoping to avoid needing to repeatedly update the position of the lines, but sounds like that's the way to go. Thanks!

Link to comment
Share on other sites

I'm having a crash in my plugin where two different event handlers — one for OnFlightReady, and one for .Net's FileSystemWatcher.Changed — call the same method, inside which is a call to ScreenMessages.PostScreenMessage(). The first one that fires is OnFlightReady, and that works fine. But the moment the second call comes as a result of the other handler, the game crashes, and I can't understand why. It's got to be the PostScreenMessage call, because if I take that call out of the method in which it appears, and just log a string instead, that works fine, multiple times, no matter which event handler it's called by. Why would two calls to PostScreenMessage crash the game?

Link to comment
Share on other sites

Actually, now that I log a string in the OnFlightReady handler and comment out the method call, the game crashes on the first execution of PostScreenMessage() in that same method, rather than the second execution, when called by the FileSystemWatcher.Changed handler. And I stress that it's not merely PostScreenMessage() that doesn't work, because it works fine when the method it's in is called by the OnFlightReady handler. It's also not the FileSystemWatcher.Changed handler by itself, since it works fine when all it does is log the message rather than putting it on the screen. It's the combination of FileSystemWatcher.Changed and PostScreenMessage(). And the crash happens even when the message displayed is identical for both handlers, and when I print a dummy string to the screen. This makes no sense to me.

I had been registering the two listeners in different places, with OnFlightReady in Start() and FileSystemWatcher.Changed in Awake(). I changed it so that both get registered in Start(), which is executed much later in the life cycle. I also put a call to PostScreenMessage() directly in each handler, so they no longer call it indirectly. This produces no change. Both handlers log that execution begins. The only difference is that an on-screen message displays just fine when done in OnFlightReady's handler, and the game crashes when the same is done in the other handler.

Link to comment
Share on other sites

  • 4 weeks later...

I am trying to change position and rotation of parts while in-flight.

My approach was to use

Part part;
Vector3 newPosition = XXX;
Quaternion newRotation = YYY;
part.transform.SetPositionAndRotation(newPosition, newRotation);

This code has the effect, that the part gets set to the new position and new rotation for a single Unity-frame. Beginning with the second frame, the part is reset to its previous position and rotation.

I conclude, that there is a functionality in place to reset the values, but I am unable to find information about this functionality. I also searched the forum and this thread for "part position transform", but could not find any information about this.

I would appreciate it, if someone could point me in the right direction of how to change the position of parts.

Link to comment
Share on other sites

  • 3 months later...
  • 4 weeks later...
  • 1 month later...
  • 3 weeks later...
On 2/22/2023 at 11:24 PM, Shantaboy said:

I've been wanting for a while to develop a mod where everytime a kerbal falls on there head (ragdolls) one science point is earned.

Any ideas on how to do this are asked and welcomed.

If Ragdoll, Then Science +1

 

Maybe try FlightGlobals:KerbalRagdollNode? I'm super new to this and I don't totally know what I'm doing so sorry if this doesn't help

Link to comment
Share on other sites

  • 1 month later...

I'd like to develop a mod that turns KSP into a Banished-like strategy game. As a first step, I'd like to implement an RTS style interface where you can control a single Kerbal's movements indirectly by clicking on the ground and having them walk there. Eventually I would like to have many Kerbals on screen at the same time all walking around independently. Any idea how I could get started on that?

Link to comment
Share on other sites

I'm trying to figure out how I could get a list of all  SpaceCenterBuilding objects within a certain radius. I know that I can get all parts within a certain radius with the code: (using KSPDev reference for KspLayerMask)

var nearestColliders = new List<Collider>(Physics.OverlapSphere(
                pos, radius, (int)(KspLayerMask.Part | KspLayerMask.Kerbal)));

I'm not exactly sure how I would be able to retrieve all buildings (i.e. VAB, SPH, etc) within the certain radius? 

Link to comment
Share on other sites

3 hours ago, WarpPrime said:

I'm trying to figure out how I could get a list of all  SpaceCenterBuilding objects within a certain radius. I know that I can get all parts within a certain radius with the code: (using KSPDev reference for KspLayerMask)

var nearestColliders = new List<Collider>(Physics.OverlapSphere(
                pos, radius, (int)(KspLayerMask.Part | KspLayerMask.Kerbal)));

I'm not exactly sure how I would be able to retrieve all buildings (i.e. VAB, SPH, etc) within the certain radius? 

You should be able to do this by testing if

collider.GetComponent<SpaceCenterBuilding> != null

 

Edited by TV4Fun
Link to comment
Share on other sites

On 5/2/2023 at 9:15 PM, TV4Fun said:

You should be able to do this by testing if

collider.GetComponent<SpaceCenterBuilding> != null

 

The only problem here is that the current list only takes parts and kerbals. I don't know if KSPDevUtils.KspLayerMask supports selecting buildings. Can you please give me something a little more specific? Thanks!

Link to comment
Share on other sites

1 hour ago, WarpPrime said:

The only problem here is that the current list only takes parts and kerbals. I don't know if KSPDevUtils.KspLayerMask supports selecting buildings. Can you please give me something a little more specific? Thanks!

All buildings and terrain are on layer 15, so you should be able to find them by setting layerMask = 1 << 15

Link to comment
Share on other sites

  • 4 weeks later...

Is there a way to conditionally load portions of your code based on what other mods are available? Like for example, I would like to have my mod support KIS if it is installed, but not require it, so I'd like to have the KIS-dependent code only load if KIS is present.

Link to comment
Share on other sites

  • 1 month later...

Anyone got an idea on how to cancel a vessel's angular velocity as soon as controls are let go (basically, so that, for example, pitching up increases the pitch angle directly instead of the angular velocity)?
I've tried things like vessel.angularMomentum.Zero() and vessel.angularVelocity.Zero(), nothing seems to work though. Closest thing I got was with setting the vessel on and off rails, but that's pretty laggy.

Link to comment
Share on other sites

  • 1 month later...

I didn't want to pollute the forum with yet another thread so i'm posting here instead.
Does anyone know how to setup RelfectionProbe to reflect dynamic objects in flight scene, not just statics (like buildings and terrain) ?
Ref:
https://docs.unity3d.com/Manual/class-ReflectionProbe.html

Please @xEvilReeperx if you have time ...

Link to comment
Share on other sites

  • 2 months later...
  • 3 weeks later...
  • 4 months later...

Is there a way to dynamically change the name of a KSPEvent the way that (for example) the "Lights on"/"Lights off" toggle switches name in the part menu depending on which state the lights are in?

Also, is there a way to dynamically show/hide different events depending on the state of the part/vessel, beyond just the guiActiveEditor vs guiActive?

I'm building a computer module and need events for actions like "Boot" and "Shutdown". Obviously those can just be the same event, but I'd like the GUI label for it  to change depending on the state of the part, rather than leaving it for the player to guess what the button will do.

I'd like to know about adding/removing or dynamically showing/hiding events because I may potentially want to add additional events where there isn't always something for the button to do in every state. If not, I can always just change the label to 'not available' or something, assuming there's a way to change the label like that.

Link to comment
Share on other sites

On 4/21/2024 at 11:53 PM, zstewart said:

Is there a way to dynamically change the name of a KSPEvent the way that (for example) the "Lights on"/"Lights off" toggle switches name in the part menu depending on which state the lights are in?

Also, is there a way to dynamically show/hide different events depending on the state of the part/vessel, beyond just the guiActiveEditor vs guiActive?

/// <summary>
        /// Shutdown/Activate BV controller
        /// </summary>
        [KSPEvent(guiActive = true, guiActiveEditor = true, guiName = "Shutdown Bon Voyage Controller", category = "Bon Voyage", requireFullControl = true)]
        public void ToggleBVController()
        {
            shutdown = !shutdown;
            Events["ToggleBVController"].guiName = (!shutdown ? Localizer.Format("#LOC_BV_ContextMenu_Shutdown") : Localizer.Format("#LOC_BV_ContextMenu_Activate"));
            if (!HighLogic.LoadedSceneIsEditor)
            {
                Fields["vesselType"].guiActive = !shutdown;
                Fields["rotationVector"].guiActive = !shutdown;
                Events["BVControlPanel"].guiActive = !shutdown;
                if (shutdown)
                {
                    if (active)
                    {
                        BVController controller = BonVoyage.Instance.GetControllerOfVessel(vessel);
                        if (controller != null)
                            controller.Deactivate();
                    }
                }
                BonVoyage.Instance.SetShutdownState(vessel.id, shutdown);
            }
            else
            {
                Fields["vesselType"].guiActiveEditor = !shutdown;
            }
        }

 

Link to comment
Share on other sites

Thanks.

When I create files with the KSP sandboxed File API, do those files get cleaned up automatically when the vessel is destroyed? If not, how can I tell when the vessel (or editor part) is gone for good so I can delete the files to avoid filling disk space indefinitely?

Alternatively, is there some other way to store particularly large chunks of vessel-related data? My mod requires storing a byte array which could be a few kilobytes or possibly low megabytes per part.

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.

×
×
  • Create New...