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
1
Question by yashesh · Nov 26, 2014 at 01:58 PM · iosplugin

Alternate to UnitySendMessage in iOS native

Hey Guys,

Currently I am working on creating a Plugin for Unity3D-iOS. I want to send data from iOS native to Unity3D. For function called from iOS native to Unity3D I need to use UnitySendMessage function. But the limitation of UnitySendMessage is that there should be some speciface GameObject there in Unity3D and it's name should be fixed and that name i have to pass in UnitySendMessage as a parameter. While in my case this solution is not suitable for me.

For example :

code in iOS (xCode) :

 [self callThisInUnity];

code in Unity3D c# :

 void callThisInUnity(){
 
    Debug.Log("Call from iOS");
 }

So if I call "callThisInUnity" function from iOS then i should be called in Unity3d.

So is there any alternate way of UnitySendMessage for sending iOS data to Unity3D ?

Thanks in advance.

Comment
Add comment · Show 2
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 FairGamesProductions · Nov 26, 2014 at 02:03 PM 0
Share

What do you mean by sending data from iOS to Unity3D?

avatar image yashesh · Nov 27, 2014 at 05:37 AM 0
Share

I want to send some text from iOS to Unity3D

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Tommynator · Nov 27, 2014 at 06:47 AM

The only alternative way I know about is to pass integers as function pointers from Unity to the native layer, recast them and store them as handles. It's pretty rough tbh, but if you're feeling so strong about not using UnitySendMessage & GameObjects - that's the way to go :)

unity code:

 class MyUnityClass
 {
    [DllImport ("iosplugin")]
    private static extern int DefinePointer(int pointer);
     
    void TestPointer()
    {
       Debug.Log("hello world");
    }
 
    void InitializePointers()
    {
       IntPtr p = Marshal.GetFunctionPointerForDelegate(TestPointer as System.Action);
 
       // pass the function pointer to the native layer
       DefinePointer(p.ToInt32());
    }
 }

iosplugin code:

 extern "C"
 {
    void DefinePointer(int pointer)
    {
       void (*unityfunc)() = reinterpret_cast<void(*)()>(pointer);
         
       unityfunc();
    }
 }

...and the unity console prints out "hello world".

In the example above I cast the pointer right away and call the function, but you can just store them in a global member and call them whenever you like.

Hope that helps ;) Cheers

Comment
Add comment · Show 7 · 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 Bunny83 · Nov 27, 2014 at 07:27 AM 0
Share

Uhm as you said that's all C#, but where is the link to iOS native code (which is probably written in objective C or C++)? AFAI$$anonymous$$ the question was about how to send text data from native code to Unity. See the plugin page.

I'm not an iOS developer so i can't say for sure, but as far as i know there's no way around using the "UnitySend$$anonymous$$essage" function. At least when it comes to "native -> Unity" communication. You might be able to call a plugin method to poll the data (so the method called simply returns the data), but as i said i don't develop for iOS.

avatar image Tommynator · Nov 27, 2014 at 07:42 AM 0
Share

cheers, good shout. See above for my updated answer.

avatar image yashesh · Nov 27, 2014 at 01:20 PM 0
Share

I want to call Unity3D function call from iOS native. Please see my updated question.

avatar image Tommynator · Nov 27, 2014 at 07:25 PM 0
Share

@yashesh: thanks for clarifying your question. :) First of all you need to write your own native library in c/c++ or objective c and define all functions that need to interoperate with Unity inside the extern "C" namespace. A good place to start is to read the unity manual section covering native plugins for iOS: http://docs.unity3d.com/$$anonymous$$anual/PluginsForIOS.html Note: It's a Pro feature and is not available in the indie version of Unity. Cheers

avatar image yashesh · Nov 28, 2014 at 05:43 AM 0
Share

@$$anonymous$$mynator I have already created iOS native plugin. I want to call $$anonymous$$y Unity Function from my iOS native plugin file.

Show more comments

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

27 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

Related Questions

Admob Plugin Unity IOS 4 Answers

Saving Unity Texture2D updated with OpenGL FBO via custom plugin 2 Answers

Plugin iOS to send Mail with MFMailComposeViewController 0 Answers

A node in a childnode? 1 Answer

UnitySendMessage and NSString allocation 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