GameFixes - Qkrisi/ktanemodkit GitHub Wiki
public static class GameFixes
Methods for working around bugs in the game that most likely won't be fixed.
The double KMSelectable.OnDefocus call
public static Action OnDefocus(Action action)
Bug description: When a selectable loses focus, the game calls the KMSelectable.OnDefocus delegate twice when it should only do so once.
References (KTANE Discord server): occurrence, cause
To work around this bug, use the above function to modify the delegate that will be added to KMSelectable.OnDefocus to make it account for the double call automatically.
Example:
GetComponent<KMSelectable>().OnDefocus += GameFixes.OnDefocus(() => {
Debug.Log("OnDefocus");
});
public static void UpdateSettings(this KMSelectable selectable)
public static void UpdateChildrenProperly(this KMSelectable selectable, KMSelectable childToSelect = null)
Bug description: Adding children to a KMSelectable by instantiating prefabs with KMSelectable components on them doesn't work.
Bug cause
When the game loads a mod, it adds the internal types to all of the prefabs in it for all the proxy types (KM...) it founds (here: KMSelectable -> ModSelectable).
The internal ModSelectable type has a method called "CopySettingsFromProxy" which copies the settings from the KMSelectable type to the ModSelectable type which are required for it to work properly.
On an instantiated prefab, these settings will most likely change (the one that really matters here is the parent setting), but the internal ModSelectable.OnUpdateChildren method would only update these settings if the selectable wouldn't have the ModSelectable component, but the component got added when the mod was laoded, thus the settings are never updated.
Reference (KTANE Discord server)
To work around this bug, use UpdateChildrenProperly
extension method, update the children correctly (including updating the settings), or use the UpdateSettings
extension method to just update the settings.
Example:
//childToSelect is optional
selectable.UpdateChildren(childToSelect); //Wrong
selectable.UpdateChildrenProperly(childToSelect); //Correct