title: How do I assign a method that is inside a prefab to the On Click() event on a button?
body: <p>I have a button that is supposed to switch beetween light and dark mode in my game by running the method &quot;ToggleTheme&quot; inside the ObjectTheme script, which all the objects that I want to be affected by light/dark mode have. ToggleTheme just changes the boolean &quot;DarkMode&quot;, since all the objects' transitions use this DarkMode boolean. It all works fine if I just assign the objects and select ObjectTheme.ToggleTheme, but if I assign the objects' prefabs and select ObjectTheme.ToggleTheme I get the warning &quot;Animation is not playing an AnimatorController&quot; on button press. Is there any way around this, because assigning every object in every scene would just be to impractical and one of the objects has up to 30 copies in every level of the game?</p>
  <p>P.S. I know It probably would have been easier if I just used a toggle instead of a button, but I'm new to Unity and I just couldn't get the toggle to work how I wanted it, so I'm using a button instead.</p>
  <p>Here is the ObjectTheme script:</p>
  <pre><code>using System.Collections;
  using System.Collections.Generic;
  using UnityEngine;
  
  public class ObjectTheme : MonoBehaviour
  {
      public Animator animator;
  
      // Start is called before the first frame update
      void Start()
      {
          animator = GetComponent&lt;Animator&gt;();
      }
  
      // Update is called once per frame
      public void ToggleTheme()
      {
           if(animator.GetBool(&quot;DarkMode&quot;) == true)
           {
              animator.SetBool(&quot;DarkMode&quot;, false);
           }
          else
           {
              animator.SetBool(&quot;DarkMode&quot;, true);
           }
      }
     
  }
  </code></pre>