diff --git a/MiraAPI/Hud/CustomButtonManager.cs b/MiraAPI/Hud/CustomButtonManager.cs index 2b09d7b..e3adae5 100644 --- a/MiraAPI/Hud/CustomButtonManager.cs +++ b/MiraAPI/Hud/CustomButtonManager.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Reflection; +using Reactor.Utilities; namespace MiraAPI.Hud; @@ -12,10 +13,16 @@ public static class CustomButtonManager { if (!typeof(CustomActionButton).IsAssignableFrom(buttonType)) { + Logger.Error($"{buttonType?.Name} does not inherit from CustomActionButton."); return; } - var button = (CustomActionButton)Activator.CreateInstance(buttonType); + if (Activator.CreateInstance(buttonType) is not CustomActionButton button) + { + Logger.Error($"Failed to create button from {buttonType.Name}"); + return; + } + CustomButtons.Add(button); typeof(CustomButtonSingleton<>).MakeGenericType(buttonType) .GetField("_instance", BindingFlags.Static | BindingFlags.NonPublic)!