Utils.Torch/VRageUtils.cs
/// <summary>
/// Get the nearest parent object of given type searching up the hierarchy.
/// </summary>
/// <param name="entity">Entity to search up from.</param>
/// <typeparam name="T">Type of the entity to search for.</typeparam>
/// <returns>The nearest parent object of given type searched up from given entity if found, otherwise null.</returns>
Get the nearest parent object of given type searching up the hierarchy.
Get the nearest parent object of given type searching up the hierarchy .
public static T GetParentEntityOfType<T>(this IMyEntity entity) where T : class, IMyEntity
        {
            while (entity != null)
            {
                if (entity is T match) return match;
                entity = entity.Parent;
            }
            return null;
        }
public static T GetParentEntityOfType < T > ( this IMyEntity entity ) where T : class , IMyEntity { while ( entity != null ) { if ( entity is T match ) return match ; entity = entity . Parent ; } return null ; }
Get the nearest parent object of given type searching up the hierarchy.
Get the nearest parent object of given type searching up the hierarchy .
The nearest parent object of given type searched up from given entity if found, otherwise null.
The nearest parent object of given type searched up from given entity if found otherwise null .
IMyEntity
this
entity
Entity to search up from.
Entity to search up from .
typeparam
Type of the entity to search for.
Type of the entity to search for .