Code:

public static H GetComponent<H>(IMyEntity entity) where H : MyGameLogicComponent { try { //Log.Info("were trying to find a component in " + entity.DisplayName + " of type " + entity.GetType().ToString()); // MyAPIGateway.Utilities.ShowNotification("searching for a hook"); if (entity == null) { Log.Info("We received no entity to check for a hook."); // MyAPIGateway.Utilities.ShowNotification("We received no entity to check for a hook"); return null; } MyEntityComponentContainer componentContainer = entity.Components; if (componentContainer == null) { Log.Info("We got no componentcontainer. Returning null."); // MyAPIGateway.Utilities.ShowNotification("We got no componentcontainer. Returning null."); return null; } H hook = null; foreach (MyComponentBase comp in componentContainer) { if (comp is H) { // Log.Info("comp is h!"); hook = comp as H; } if (comp is MyCompositeGameLogicComponent) { // Log.Info("we got a composite component!"); // MyAPIGateway.Utilities.ShowNotification("we got a composite component!"); hook = comp.GetAs<H>(); } } if ((hook == null)||(DEBUG)) { Log.Info("We did not find our Hook."); // MyAPIGateway.Utilities.ShowNotification("We did not find our hook."); Log.Info("This is what we had: "); foreach (MyComponentBase comp in componentContainer) { Log.Info(comp.ToString()); } } return hook; } catch (Exception e) { Log.Info(e.ToString()); return null; } }