Jump to content

Hook into Part.onCopy from PartModule


marce

Recommended Posts

Second problem but not related to my other one so I create a second thread :)

Question: is it somehow possible to hook into the onCopy method of part from a PartModule?

Background: I have to reset attributes of the module when its part is copied. I'd like to avoid subclassing Part itself and stay with a Module.

I experimented with reset onAttach and other stuff like that but then it did it also when moving the original part etc.

So I'd really like to get an info when the part has been cloned (also considering symmetry) in order to clean up.

Link to comment
Share on other sites

I don't know if onCopy is setup for a call back, but I do know part.onAttach and part.onDetach are.

In your partmodule, if you run this:

{code here to insure this line only runs once}
part.onAttach += OnAttachCode();


OnAttachCode()
{
--code here to run when the part that the partModule is assigned to gets attached.
}

OnDestroy()
{
part.onAttach -= OnAttachCode(); //remove the callback when the part destroyed
}

If this works for part.onCopy, it sounds exactly like what you are looking for.

Link to comment
Share on other sites

Sadly this doesn't work for onCopy.

I added a workaround consisting of IDs and generating vessel part lists...

How easy modding KSP could be without all those silly limitations :(

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