Bug #10247
IMassModifier/ICostModifier called before PartModule OnLoad/OnStart - being called on uninitialized modules.
100%
Description
As per the title, IMassModifier/ICostModifier is often called before parts are fully initialized, resulting in inconsistent reporting of mass and/or cost for modules that rely on internal state for their modifications.
This is making it difficult to properly modify the mass for the editor display icon and results in improper mass for the first few physics ticks(perhaps only one tick) of flight for a craft.
Expected behavior: IMassModifier/ICostModifier methods are only called on fully initialized PartModules (e.g. they have had both OnLoad/OnStart called).
Actual behavior: IMassModifier/ICostModifier are called prior to PartModules having initialization methods called on them, resulting in those that rely on state data to have no information on how they are supposed to modify mass/cost.
History
#2 Updated by ShotgunNinja about 8 years ago
I don't know if is relevant, but OnLoad() is not called in the editor when you add a part.
Instead, the following happen:
- at part compilation time (loading screen):
- OnLoad() is called
- GetInfo() is called, the result stored in part info
- GetModuleCost()/GetModuleMass() are called, the result stored in part info (the total for the part)
- when adding a part in the editor:
- part is copied from prefab (by first serializing it to binary data, then deserializing it in the clone)
- OnStart() is called
- inside the editor, if GetModuleCostChangeWhen()/GetModuleMassChangeWhen() return ModifierChangeWhen.CONSTANTLY:
- GetModuleCost()/GetModuleMass() are called every frame, the vessel cost and mass updated correctly
#3 Updated by Squelch about 8 years ago
- Status changed from New to Ready to Test
- Target version set to 1.2.0
- % Done changed from 0 to 80
I understand that this has now been found to be working correctly in KSP 1.2
#4 Updated by shadowmage45 about 8 years ago
Squelch wrote:
I understand that this has now been found to be working correctly in KSP 1.2
Indeed, I was unable to replicate it in the latest pre, or 1.2 actual release.
#5 Updated by Squelch about 8 years ago
- Status changed from Ready to Test to Resolved
- % Done changed from 80 to 100
Thanks shadowmage45.
I'll mark this as resolved now.
#6 Updated by JPLRepo about 8 years ago
- Status changed from Resolved to Closed