-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Framerate drops while hovering over inventory #2
Comments
FindObjectsOfType() call in ModuleKISInventory.cs:835 seems to be the cause of this. Functions like Object.FindObjectsOfType(), Resources.FindObjectsOfTypeAll() etc. are extremly slow and should be avoided whereever possible, especially in methods that are called per-frame. A single such call per frame has drastic impact on framerate. |
I've gotten this as well. Theres also some camera wierdness going on in the VAB.SPH that might be related. The lag is particularily bad when at a base that is already laggy |
The call to FindObjectsOfType in ModuleKISInventory can be eliminated by adding a component to the window prefab which updates a static list of open UIPartActionWindows. Example: [KSPAddon(KSPAddon.Startup.EditorAny, true)]
public class InitPartActionWindowTracker : MonoBehaviour
{
private void Awake() { UIPartActionWindowTracker.Init(); }
}
[KSPAddon(KSPAddon.Startup.Flight, true)]
public class FlightBootstrapper : InitPartActionWindowTracker
{
}
public class UIPartActionWindowTracker
{
private class WindowTrackerComponent : MonoBehaviour
{
private void Awake() { Add(GetComponent<UIPartActionWindow>()); }
private void OnDestroy() { Remove(GetComponent<UIPartActionWindow>()); }
}
public static readonly List<UIPartActionWindow> Windows = new List<UIPartActionWindow>();
public static void Init()
{
if (UIPartActionController.Instance.windowPrefab.gameObject.GetComponent<WindowTrackerComponent>() == null)
UIPartActionController.Instance.windowPrefab.gameObject.AddComponent<WindowTrackerComponent>();
}
private static void Add(UIPartActionWindow window)
{
if (window != null && !Windows.Contains(window))
Windows.Add(window);
}
private static void Remove(UIPartActionWindow window)
{
if (window != null && Windows.Contains(window))
Windows.Remove(window);
}
} Then this line:
could be changed to
and avoid the performance penalty |
Fixed for next version (1.0.1) |
Significant framerate drop (to only a few frames per second) occurs when hovering a mouse cursor over an inventory window during the flight scene.
There are no messages printed to the log. It only occurs during flight, it works fine in editor.
The text was updated successfully, but these errors were encountered: