Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by Brokenarrow · Sep 04, 2015 at 10:26 PM · functionmethodcheckinvokecall

Is there any way to check which method called a certain other method?

Question says it all. I currently have a set of methods that call other methods. However these other methods are only very slightly different. If I can determine which method called a certain method I could condense all these other methods into one with an if-else structure.

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Scribe · Sep 05, 2015 at 04:15 PM 0
Share

If it is just for identifying what needs to be changed and not to be used in runtime, you could get the traceback. In fact, if you just add a Debug.Log() and expand your console a little, it shows where it came from, which may be useful!

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by kbumpious · Sep 04, 2015 at 11:28 PM

Pass a string from one function to the other.

 void func1 (){
      func3("itwasfunc1");
 }
 
 void func2 (){
      func3("itwasfunc2");
 }
 
 void func3 (string thefuncthatcalledme){
      Debug.Log(thefuncthatcalledme);
 }
Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Brokenarrow · Sep 05, 2015 at 11:59 AM 0
Share

How would I go about it if I used Invoke to call the other method?

 void LaunchShipA() 
     {
         Invoke ("ALaunch", (Random.Range(0, 10)));
     }
 
 void LaunchShipB() 
     {
         Invoke ("ALaunch", (Random.Range(0, 10)));
     }
         
     void ALaunch()
        {
         Rigidbody clone;
         clone = Instantiate(enemyShip, spawnPointArray[0], transform.rotation) as Rigidbody;
        }
avatar image kbumpious · Sep 05, 2015 at 03:05 PM 0
Share

I am not sure on the neatest way to do it in that case. What I would do is just create a public variable and change the value of that in your functions and then log it from your ALaunch function:

 public string whoLaunched;
     
 void LaunchShipA() 
      {
          Invoke ("ALaunch", (Random.Range(0, 10)));
          whoLaunched = "ShipA";
      }
  
  void LaunchShipB() 
      {
          Invoke ("ALaunch", (Random.Range(0, 10)));
          whoLaunched = "ShipB";
      }
          
  void ALaunch()
     {
          Debug.Log(whoLaunched);
          Rigidbody clone;
          clone = Instantiate(enemyShip, spawnPointArray[0], transform.rotation) as Rigidbody;
     }

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

29 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How can I call a method from another script? 3 Answers

How to check if a function is called? 2 Answers

Calling Function in other Script via Touch => iOS Crash 1 Answer

Calling A Function Once 0 Answers

Calling a function only once in Update 3 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges