- Home /
UnitySendMessage does and doesn't recognize receiver in 2 similar instances
edit
So i guess i've figured out what the problem is, i've assigned the MonoBehaviour also on the GameObject that is in the the level targeted for loading. Turns out that the message telling there's no receiver is actually responding to the GameObject that is in the loaded level. So the level is loaded, but it isn't being displayed. Which makes me think that creating the MPMoviePlayer does eliminate the 'thing' 'component', that is responsible for rendering. Anyone has any thoughts on that ?
I'm writing a small plugin for streaming video native on iOS, and am stuck on an issue with the native code.
When streaming the video the fuction detects for swipes and if so calls on a method called loadLevelNative that sends a message to some GameObject that has a script assigned containing the function public void loadLevelUnity(string str); All this does is load another level like so Application.LoadLevel(str);
The weird thing is that if i send the message in a function declared as C by placing it in an extern "C" block. And let it just do that, it works fine .. the designated level is instantly loaded... so far so good. This however is of course not what i want, the way its supposed to work is having the UISwipeGestureRecognizer added to the movieplayer which calls on a method that sends the message. All this is working... however the Xcode output tells me that in this instance that "SendMessage: object GameObject does not have receiver for function loadLevelUnity!" I fail to understand why..., it does recognize the GameObject fine.
I named the GameObject, GameObject so if i change to SendMessage parameter to something else, say ObjectGame then there's a message that object "ObjectGame" cannot be found, this all speaks for itself but i figured to be as clear as possible.
So to surmise, if UnitySendMessage is called from the method assigned to the gesture recognizer then it won't receive the public function on the GameObject, and i can't figure out why. I'm hoping some of you can help me out here
Its a tiny bit of code (VideoPlugin.mm), i've put it up here : http://pastebin.com/DWbh8mRz
The native code comment is a leftover of the bonjour plugin sample that i used as a template, i left it in there for clarity.
loadLevelUnity is simply this:
public void loadLevelUnity(string str)
{
Application.LoadLevel(str);
}
and finally the interface defined in VideoPlugin.h
@interface VideoPlugin : UISwipeGestureRecognizer
- (void)loadLevelNative;
@end
This is the code of the Unity MonoBehaviour that is attached to GameObject named GameObject in my scene.
using UnityEngine;
using System.Collections;
public class vidtest : MonoBehaviour {
public void loadLevelUnity(string str) {
Application.LoadLevel(str);
}
void Start () {
VideoPlugin.playVideo("http://www.royniginal.nl/small.mp4");
}
}
And this is the code that interfaces with the native code, its in a separate file.
using UnityEngine;
using System.Collections;
using System.Runtime.InteropServices;
public class VideoPlugin {
/* Interface to native implementation */
[DllImport ("__Internal")]
private static extern void _playVideo (string videoFilepath);
/* Public interface for use inside C# / JS code */
public static void playVideo(string videoFilepath) {
if (Application.platform != RuntimePlatform.OSXEditor)
_playVideo(videoFilepath);
}
}
What is even weirder to me, is that i change the third argument of UnitySendMessage to the name of a level that isn't in the build settings i get a message in Xcode output saying " Level 'pictureLoad' (-1) couldn't be loaded because it has not been added to the build settings. " Yet if that parameter is set up correctly i get a message that the GameObject has no receiver for the function that loads the level ?
Stop spam$$anonymous$$g. You posted this question 10 times!!!
Format your code. Its hard to read code after someone especially if it is posted in such unreadable state. $$anonymous$$ake your post nicer and you will get better results.
I've posted it twice, once on the forum and once here. I'll format the code, right now.
You posted it here 10 or eleven times. I know. Because i had to decline all but one of them...
What are you talking about ? I wrote the post once and clicked Ask your question. If thats true, there must be something going wrong with the system i guess...
$$anonymous$$ight be. But i havent seen it before.
You're question looks nice now. Good job.
Your answer
![](https://koobas.hobune.stream/wayback/20220613103706im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
iOS modal viewcontroller disappears 0 Answers
Use of Unity ads in Native Apps IOS 0 Answers
iOS Music Control 0 Answers
How can I get/set iOS Alarms? 1 Answer
Need help ios native share 1 Answer