ferram4 / Ferram-Aerospace-Research

Aerodynamics model for Kerbal Space Program
Other
237 stars 131 forks source link

MonoBehaviour without a GameObject #205

Open blowfishpro opened 7 years ago

blowfishpro commented 7 years ago

Here:

https://github.com/ferram4/Ferram-Aerospace-Research/blob/d82a3a4282e72a9488ba98045c59b7d2e56fc3d5/FerramAerospaceResearch/FARSettingsScenarioModule.cs#L108

FAR creates a new FARSettingsScenarioModule using the constructor. But ScenarioModule derives from MonoBehaviour, which shouldn't exist unless attached to a GameObject.

I think this code is only hit in the incompatible case, which is why it has worked up until now. I also don't think there's any need to manage a ScenarioModule's lifecycle manually - KSP should (at least in theory) take care of all that.

ferram4 commented 7 years ago

I believe this code is necessary though, because I remember putting this in to make sure that training missions and scenarios outside of the main save games work properly. I've never seen any errors or exceptions thrown from it either.

blowfishpro commented 7 years ago

The exception actually occurs here (inside Unity)

https://github.com/ferram4/Ferram-Aerospace-Research/blob/d82a3a4282e72a9488ba98045c59b7d2e56fc3d5/FerramAerospaceResearch/FARSettingsScenarioModule.cs#L125

but I can't see that happening unless the object isn't created correctly.

Everything I've seen suggests that a MonoBehavior must always be attached to a GameObject. Have you seen something different?

NathanKell commented 7 years ago

Yeah, generally if you try to do that Unity complains loudly. Certainly if you do that in the editor it does! You should add it to the scenariorunner gameobject probably?