Jump to content

Any way to detect model loading?


Recommended Posts

I have a model that I'm scaling to several different sizes via MODEL { scale }. The problem is, the emitters for models are not scaled by KSP, which has me doing so in the PartModule for my plugin. While this works as I'm currently doing it in OnStart(), it presents a problem in that the emitters are not re-scaled if the parts are reloaded via the debug menu. So, is there a way to detect that the model is being reloaded, and scale my emitters appropriately again?

Edit: Actually I realized that they way I'm doing it now doesn't work correct either, even without reloading parts, as when you copy a part the scaling is reapplied. So, where is the correct place to apply such a scaling factor?

Edit2: I managed to work around the scaling bug while copying with a public flag to check if it has already been scaled, but it doesn't help with the scaling issues associated with reloading the parts library.

Edited by Orum
Link to comment
Share on other sites

Alright, apologies for the double-post but I think I might have figured out what's going on. My assembly is actually being unloaded due to a "System.IO.IOException: Sharing violation" (not sure why that's happening, but I have theories), so it can't perform its internal scaling code when the parts are reloaded.

Additionally I bugged Mu on IRC about MODEL{ scale } working for emitters, and he seemed optimistic about fixing it, so hopefully that will happen too.

Link to comment
Share on other sites

  • 2 weeks later...

Okay, apologies for triple-posting, but I found a new problem. Though what I had works when grabbing new parts from the catalog, and when alt-clicking, it doesn't work when loading the parts from a save.

Currently what I have is something like this:

public class foo : PartModule {
public bool b = true;
float sf = 2.0; // This is actually loaded from the cfg file, it's just defined here for brevity

public override void OnStart(StartState ss) {
if( {
b = false;

foreach(KSPParticleEmitter kpe in part.GetComponentsInChildren<KSPParticleEmitter>() ?? new KSPParticleEmitter[0]) {
kpe.shape3D *= sf;
kpe.shape2D *= sf;
kpe.shape1D *= sf;
kpe.minSize *= sf;
kpe.maxSize *= sf;
kpe.rndVelocity *= sf;
kpe.localVelocity *= sf;
kpe.force *= sf;
kpe.rndForce *= sf;
}

foreach(Light l in part.GetComponentsInChildren<Light>() ?? new Light[0])
l.range *= sf;
}
}
}

Example image of before and after loading.

So, is there any way to do this correctly so both loading and editing of parts work correctly? It's a showstopper for the release of my parts/plugin right now. :mad:

Edit: Okay, after more hours of debugging than I care to admit to, I finally figured out what's going on. GetComponentsInChildren is NOT restricted to GOs in the current part instance, as I thought--it's searching the entire vessel tree and looking for all GOs in all "Child" part instances--not just the current part. I'm trying to find a way to just search child GOs within the current part instance.

Edited by Orum
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...