title: Template function to FindComponentByClass in Unreal Engine
body: <p>I'm trying to define a function to take UActorComponent as an argument and use FindComponentByClass to initialize based on its classType, so I used template as follow:</p>
  <pre><code>template&lt;class T&gt;
  void FindActorComponent(T *aComponent){
      aComponent = GetOwner()-&gt;FindComponentByClasss&lt;T&gt;();
      if(aComponent) //doSomething;
      else //doOther;
  }
  </code></pre>
  <p>However, I found that the passed object by pointer(aComponent) came out nullptr from function, although it's not after initializing inside it!</p>
  <p>So, I searched for a solution for the situation and found this:
  <a href="https://stackoverflow.com/questions/10240161/reason-to-pass-a-pointer-by-reference-in-c">Pass pointer by reference</a>, and after trying it by changing the argument from (T *aComonent) to (T *&amp;aComponent) I found it working!</p>
  <p>Can anyone explain to me the concept behind this, and why it didn't affect the passed object although it's passed by pointer?</p>
  <p>Also if I want to execute some functions based on passed class type(like if it's UInputComponent to BindAction), how should I do this? I tried to use GetClass() but I couldn't go anywhere with it!</p>
  <p>Thanks in Advance.</p>