- Home /
Invoke scope
I think this might be a scope issue but I want to sure and/or find a better way to do it.
What I want but doesn't work:
     void SuperCoolFunction ()
     {
 
             Invoke("Someobject.SomeMethod", 2); // run method of object
 
     }
Returns after 2 seconds "Trying to Invoke method: Someobject.SomeMethod couldn't be called."
But this code did work:
 void SuperCoolFunction ()
         {
     
                 Invoke("ThisOtherFunction", 2); // run method of object
     
         }
 
 void ThisOtherFunction () {
                 Someobject.SomeMethod();
 }
This has nothing to do with scope. Invoke wants the name of the function, and nothing else. Invoke is not able to handle the name of your object references .
Answer by UnityCoach · Jun 16, 2017 at 03:42 PM
Invoke is called on a MonoBehaviour. You may do :
 ThisOtherComponent.Invoke ("Method", 2);
Same goes with SendMessage and BroadcastMessage.
Consider using interfaces if you want to call methods of other components.
Your answer
 
 
             Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Enum with multiple fields 2 Answers
Does Garbage Collector Collect variables Made Inside Scope? 1 Answer
Identify Each IEnumerator Uniquely 0 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                