Jump to content

Any way to switch MODULEs in-game?


Stone Blue

Recommended Posts

I dont suppose there is any way to switch MODULEs in-game, like you can meshes/textures/etc?

And yes, I know you can use MM to change/edit them at load time... I'm looking for a way to assign different MODULEs in the editor... Hopefully just using sliders in the rt-clk menu, but a seperate GUI would be OK...

Edited by Stone Blue
Link to comment
Share on other sites

16 minutes ago, Benjamin Kerman said:

Maybe Part.AddModule or something like that. This sounds a great way to get an introduction to modding!

Thanx :)
...but i should have added that I cant code (having enough trouble learning modeling/texturing, and advanced cfg/MM patching)...So I'm hoping for a ready-made solution :P ...

Link to comment
Share on other sites

Technically - yes, you can change MODULEs through plugin code.

Realistically - no way; the stock code expects the same modules that are on the prefab part to be present on the runtime part.  Otherwise it causes all sorts of grief with loading/saving/persistence, and especially problems with other mods' interaction with those parts (as other mods also expect MODULES to not change).

Source:   I have spent at least two years trying to get run-time module switching to work reliably.  It doesn't.  I can get it working for very specific use-cases with the caveat that there are compatibility issues with other mods and stock code quite often (see the SSTU parts with optional/switchable docking ports).

 

Link to comment
Share on other sites

1 minute ago, Stone Blue said:

to see if I can copy/add some code from another mod to handle in-editor color changing... :P

:)

That is an entirely different beast, but also something I have quite a bit of experience with.  Quite a complicated undertaking -- requires knowledge of shader code, Unity internals, modeling/texturing, and how everything comes together to work in KSP.

(I recently added a part recoloring system to SSTU that handles most parts; feel free to use that as a starting point for your work, it is all open-source licensed code)

Link to comment
Share on other sites

@Shadowmage Well, the plugin I'm dealing with is AviationLights... The color setting is defined in a cfg node... So I'm guessing I wouldnt need to mess with shaders, Unity & all that... Unfortunately though, the MODULE is custom... I just need a way to select/switch color change in the editor, like stock and SurfaceLights, and a few other mods with light parts do...rather than thru MM patching... I'm trying to make it so I'm only having to define three parts, rather than being stuck with having to have seven actual, identical parts just because of different color...

I dont want to hit up MOARdV with it, since I know he's busy with other stuff, and he has said he's only maintaing the mod, and doesnt want to put the time in on adding features... And I completley dont blame him... :)

But Thanx for the offer of checking out your code...I certainly will do that.. :)

Edited by Stone Blue
Link to comment
Share on other sites

54 minutes ago, Stone Blue said:

@Shadowmage Well, the plugin I'm dealing with is AviationLights... The color setting is defined in a cfg node... So I'm guessing I wouldnt need to mess with shaders, Unity & all that... Unfortunately though, the MODULE is custom... I just need a way to select/switch color change in the editor, like stock and SurfaceLights, and a few other mods with light parts do...rather than thru MM patching... I'm trying to make it so I'm only having to define three parts, rather than being stuck with having to have seven actual, identical parts just because of different color...

I dont want to hit up MOARdV with it, since I know he's busy with other stuff, and he has said he's only maintaing the mod, and doesnt want to put the time in on adding features... And I completley dont blame him... :)

But Thanx for the offer of checking out your code...I certainly will do that.. :)

 

Ahh, yes, something like that would be quite a bit simpler than the system I had to implement.  In theory it should be able to be done by some very simple edits to the modules code to add UI elements to control the colors; in theory....

(but it will still require plugin/coding work regardless; module-manager can only change things during initial loading; once it is loaded it is 'set in stone' as far as MM is concerned)

 

Looking at the actual code -- it really wouldn't take very much to make the colors user-configurable.   Three new float fields (red, green, blue) with UI_FloatRange on them, a change to the existing Vector3 Color variable to add an 'isPersistant = true', and a few (maybe 6?) lines of code to handle the load/save of the data (load from the Vec3 into the floats, save from the floats into the Vec3).  If compatibility wasn't an issue, you could just change over to having the 3 float fields as persistent, slap on the UI tags, and call it good.

(While I could write up and submit a PR for the work in just a few minutes... I don't have time to do any testing on it myself... and I personally consider it quite rude to submit PRs without thorough testing beforehand)

Link to comment
Share on other sites

44 minutes ago, Shadowmage said:

In theory it should be able to be done by some very simple edits to the modules code to add UI elements to control the colors; in theory...

Thats what I was hoping/thinking... Thanx for confirming it tho :D

44 minutes ago, Shadowmage said:

Three new float fields (red, green, blue) with UI_FloatRange on them, a change to the existing Vector3 Color variable to add an 'isPersistant = true', and a few (maybe 6?) lines of code to handle the load/save of the data (load from the Vec3 into the floats, save from the floats into the Vec3).  If compatibility wasn't an issue, you could just change over to having the 3 float fields as persistent, slap on the UI tags, and call it good.

Heh... That paragraph is complete Greek to me... :P

44 minutes ago, Shadowmage said:

(While I could write up and submit a PR for the work in just a few minutes...

No prob... Not really looking for someone to DO this for me... Was just thinking if there WAS already a way to do what I need, no use waiting on learning to do it for myself, only to then end up reinventing the wheel, so to say...
Been using this mini-mod as a learning tool, and I do eventually hope to dabble with some code, and this one does seem pretty small and lite... IF (a big if), I get to the point where I understand the whole plugin, I might ask MOARdV if I could take it off his hands...

I'll leave the color-changing on the back burner for now I guess... Then I ust have one issue to figure out with B9 and Firespitter mesh switching, then I can release an update, then maybe poke around the code for the NEXT release...

Anyway, as always, Thanx a bunch for the responses...

Edited by Stone Blue
Link to comment
Share on other sites

On 9/1/2017 at 8:11 AM, Stone Blue said:

I dont suppose there is any way to switch MODULEs in-game, like you can meshes/textures/etc?

And yes, I know you can use MM to change/edit them at load time... I'm looking for a way to assign different MODULEs in the editor... Hopefully just using sliders in the rt-clk menu, but a seperate GUI would be OK...

Wild Blue Tools has done this since 2014... :) Sorry, that was a bit off the cuff. Take a look at WBIModuleSwitcher in Wild Blue Tools. WBT isn't well documented, but if you have questions I'll be happy to answer them. :)

Edited by Angel-125
Link to comment
Share on other sites

3 minutes ago, Stone Blue said:

:P

Hmmm... Not sure it will do ME much good tho... I'll have to look back and see why I might not be able to use it for the mesh-switching...

No worries. For mesh-switching, I have a simpler plugin I did for the KSP Part Overhauls. You can find that code here and the release dll here. I am doing some revisions in the next couple of days so that the resource switcher can sync with the mesh switcher, and vice-versa. WBT also has mesh switching but it's overkill if all you want is resource and mesh switching. I might add in texture switching too.

Edited by Angel-125
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...