Jump to content

OnFixedUpdate and staging


Recommended Posts

Hello everyone,

I am noticing something very weird on my PartModule

From my logs, it appears that the OnFixedUpdate method is only called when the part it is attached to is in the active stage.

Is it by design? Or am I doing something wrong?

Link to comment
Share on other sites

Oh sry, you didn't knew. KSP uses Unity and Unity does stuff the Unity way. Their messages don't require you to "overwrite" anything. The class just needs to have a method with such a name and signature. It doesn't even have to be public. Unity will call it via evil magic you probably don't want to hear about. Check out some other mods in case you want some examples. Even usual non-part KSPAddons are MonoBehaviours, just like PartModule is.

Link to comment
Share on other sites

OH. MY. GOD.

Like, seriously!? This really confuses me a lot, but it works :P

Well, of course now I get a huge stream of NRE because I have to initialize stuff, but as soon as I launch and they get set, it all starts working like a charm. :D

I'm a little confused on why this works (I guess that Unity actually checks via reflection if I defined a FixedUpdate() ), but nontheless, it does, and that's all I care about right now :P

You, sir, just saved my mod. Here, have some rep :)

Link to comment
Share on other sites

Yes, it uses Reflection. You just need to do "private void FixedUpdate()" and the method will be called every physics frame. Actually it could be any member access modifier and it would work. This works for every class who inherits MonoBehaviour in some way, and PartModule does.

If you want the full list of methods you can define this way, you can find them here under "Messages": http://docs.unity3d.com/ScriptReference/MonoBehaviour.html

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