f111fei / react-native-unity-view

Show an unity view in react native
MIT License
402 stars 102 forks source link

SendMessage: object UnityInterface not found! #56

Open im-aditya opened 6 years ago

im-aditya commented 6 years ago

I am facing 2 scenarios on iOS:

  1. I build the project and the app starts on my device. Then all my react components are being rendered. I am getting componentDidMount of UnityView. And I have set a reference to UnityView also. After that if I am calling any function on the UnityView, the function is getting executed. This is all fine, except that I am not getting any messages from the Unity side to react side.

Also if I set Debug logs in the Unity onStart functions, I am not getting those logs as well. BUT the function calls are getting executed.

  1. I build the project and the app starts. All my react components are being rendered. I get componentDidMount of UnityView and once the reference is set I call some functions on the UnityView. BUT my functions are not getting called inside Unity. I get this in my console logs (xcode)
-> applicationDidBecomeActive()
Renderer: Apple A9 GPU
Vendor:   Apple Inc.
Version:  OpenGL ES 2.0 Metal - 50.8
GLES:     2
GL_OES_depth_texture GL_OES_depth_texture_cube_map GL_OES_depth24 GL_OES_element_index_uint GL_OES_fbo_render_mipmap GL_OES_mapbuffer GL_OES_packed_depth_stencil GL_OES_rgb8_rgba8 GL_OES_standard_derivatives GL_OES_texture_float GL_OES_texture_half_float GL_OES_texture_half_float_linear GL_OES_vertex_array_object GL_EXT_blend_minmax GL_EXT_color_buffer_half_float GL_EXT_debug_label GL_EXT_debug_marker GL_EXT_discard_framebuffer GL_EXT_draw_instanced GL_EXT_instanced_arrays GL_EXT_map_buffer_range GL_EXT_occlusion_query_boolean GL_EXT_pvrtc_sRGB GL_EXT_read_format_bgra GL_EXT_separate_shader_objects GL_EXT_shader_framebuffer_fetch GL_EXT_shader_texture_lod GL_EXT_shadow_samplers GL_EXT_sRGB GL_EXT_texture_filter_anisotropic GL_EXT_texture_rg GL_EXT_texture_storage GL_APPLE_clip_distance GL_APPLE_color_buffer_packed_float GL_APPLE_copy_texture_levels GL_APPLE_framebuffer_multisample GL_APPLE_rgb_422 GL_APPLE_sync GL_APPLE_texture_format_BGRA8888 GL_APPLE_texture_max_level GL_APPLE_texture_packed_float GL_IMG_r
ead_format GL_IMG_texture_compression_pvrtc 
OPENGL LOG: Creating OpenGL ES 2.0 graphics device ; Context level  <OpenGL ES 2.0> ; Context handle -1071454144
Initialize engine version: 2018.1.8f1 (26051d4de9e9)
2018-09-20 02:17:53.481 [info][tid:com.facebook.react.JavaScript] '[ConnectionHandler] App state change | Current:', 'unknown', 'Next:', 'unknown'
2018-09-20 02:17:53.482 [info][tid:com.facebook.react.JavaScript] '[ConnectionHandler] App state change | Current:', 'unknown', 'Next:', 'active'
SendMessage: object UnityInterface not found!
SendMessage: object UnityInterface not found!
SendMessage: object UnityInterface not found!
SendMessage: object UnityInterface not found!
2018-09-20 02:17:53.484 [info][tid:com.facebook.react.JavaScript] '[Utils] Setting previous screen:', 'Onboarding'
UnloadTime: 1.983750 ms
[UnityInterface] Start
UnityEngine.DebugLogHandler:Internal_Log(LogType, String, Object)
UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
UnityEngine.Logger:Log(LogType, Object)
UnityEngine.Debug:Log(Object)
UnityInterface:Start()

(Filename: /Users/builduser/buildslave/unity/build/Runtime/Export/Debug.bindings.h Line: 43)

[Unity] Start
UnityEngine.DebugLogHandler:Internal_Log(LogType, String, Object)
UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
UnityEngine.Logger:Log(LogType, Object)
UnityEngine.Debug:Log(Object)
Charactor:Start()

(Filename: /Users/builduser/buildslave/unity/build/Runtime/Export/Debug.bindings.h Line: 43)

2018-09-20 02:17:53.910 [info][tid:com.facebook.react.JavaScript] '[CharacterUnityView] On Unity message', 'onInterfaceStart'
2018-09-20 02:17:53.911 [info][tid:com.facebook.react.JavaScript] '[CharacterUnityView] On Unity message', 'onStart'
Setting up 1 worker threads for Enlighten.
  Thread -> id: 170b03000 -> priority: 1 

I am getting all the messages from UnitySide. After these calls are done, now if I call any functions on the UnityView, they are getting executed.

Why am I not getting a consistent behaviour ? In one scenario I am calling unity functions and they are immediately getting executed. On the other hand I am getting this error. How do I always get some callback from the Unity side that everything is set and I can start calling functions on the UnityView component ?

shhhiiiii commented 3 years ago

Im experiencing this scenario also, On first unity load its working perfect, then I used Application.Unload(); to unload unity and navigate to other react native screen, When navigate again to unity view, Unity will reload just fine and will work properly,

But the problem is that messaging is distorted. Unity still can send message and will be receive in react native side, But for react native part when attempt to send message to unity view. Unity will not be able to receive the message.

Im suspecting that react native still trying to send message from the previous view that has been unload.

Does anyone know how to fix this problem?

HELP PLEASE!!