title: How to reference overridden generic method local parameter?
body: <p>I have a main class that looks like this:</p>
  <pre><code>public abstract class Soldier : Monobehaviour
  {
  public virtual T GetClosestEnemy&lt;T&gt;(T soldierType) where T : MonoBehaviour
  {
      T[] soldiers;
      soldiers = FindObjectsOfType&lt;T&gt;(soldierType);
      T closestSoldier = null;
      float dist = Mathf.Infinity;
      Vector3 thisPos = transform.position;
      foreach(T soldier in soldiers)
      {
          print(&quot;looping&quot;);
          Vector3 difference = soldier.transform.position - thisPos;
          float currentDist = difference.sqrMagnitude;
          if (currentDist &lt; dist)
          {
              print(&quot;found it&quot;);
              closestSoldier = soldier;
              dist = currentDist;
          }
      }
      print(closestSoldier.gameObject.name);
      return closestSoldier;
  }
  }
  </code></pre>
  <p>And here is the derived class:</p>
  <pre><code>public class GoodSoldier : Soldier
  {
      public BadSoldier closestBadSoldier = null;
  
  public override BadSoldier GetClosestEnemy&lt;BadSoldier&gt;(BadSoldier soldierType)
  {
      
      return base.GetClosestEnemy(soldierType);
  }
  void Update()
  {
       GetClosestEnemy&lt;BadSoldier&gt;(closestBadSoldier);
      
  }
  }
  </code></pre>
  <p>The base method works just fine. I reference it in the subclass and it also works just fine. It prints the right object's name. But closestBadSoldier is still null. How can that even be possible? I can't reference it in any other methods or it gives me a Null Reference Exception.</p>