Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
0
Question by Cannata · Apr 02, 2014 at 08:44 PM · c#androidfunctionstatic

How do you call a static function in C# from Android?

We used to use instance methods in C#, but changed them to static methods. This is fine for the iOS guys who are using mono methods to call back to the native code, but I don't know how to accomplish this in Android. Before we were using UnitySendMessage, but this needs an object to call it on. How do I call a static class method in C# from Android with the least effort. I'll provide an example of what I mean. Thank you!

C#:

 public class Example : MonoBehaviour
 {
     public static void DoStuff(string text)
     {
          // Do stuff with text
     }
 }

Java:

 public class Test
 {
    // Call C# static method
    // Used to use UnityPlayer.UnitySendMessage when method was instance
 }
Comment
Add comment · Show 3
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 Owen-Reynolds · Apr 03, 2014 at 05:47 AM 0
Share

What's wrong with the usual way, Example.DoStuff();?

avatar image flamy · Apr 03, 2014 at 05:50 AM 0
Share

i hope he wants to call a function in the plugin.

avatar image Cannata · Apr 03, 2014 at 05:30 PM 0
Share

I want to call Example.DoStuff(), but that is in C# code and I don't know how to access that from Java.

1 Reply

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

Answer by Owen-Reynolds · Apr 03, 2014 at 09:59 PM

I feel like I'm missing something (a Java plugin?) But, you say you can use UnitySendMessage to run functions on scripts on gameObjects. So, could launder calls to statics through drivers on dummy(empty) gameObjects:

 public class CallStaticsForPlugIn : Monobehave {
   public void doStuff(string text) { Example.doStuff(text); }
 }

If all the statics are in MonoBehave classes (like the example above,) could just put that driver next to the static (maybe call it "runDoStuff".)

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 Cannata · Apr 03, 2014 at 10:14 PM 0
Share

Thank you. That was one of our thoughts, but we have so many functions in so many places to call, that this would get very large. So was hoping there was an alternative.

avatar image Owen-Reynolds · Apr 04, 2014 at 02:31 PM 0
Share

Sounds like the real solution is letting the code-monkeys know they aren't in charge, and need to run big changes past everyone it will affect. Seriously, some of the worst student projects I saw were when the only talented programmer was also the lead, and went down a rabbit hole of "fun to write" code.

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

22 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

Related Questions

Distribute terrain in zones 3 Answers

Acces an Awake variable 2 Answers

Multiple Cars not working 1 Answer

an object reference is required for the non static field error 1 Answer

instantiate random prefabs based on player camera distance 1 Answer


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