Is low level native plugin working in Apple VisionOS? I tried but the UnityPluginLoad function is never called.
Hi there! Thanks for reaching out and sorry to hear you’re having trouble.
How have you implemented this native plugin? Did you base it on the NativeRenderingPlugin example? You should be able to follow what is implemented there for iOS to get things working. In particular, note the extra RegisterPlugin.mm file included to explicitly call UnityPluginUnload at the appropriate time. This is also necessary on visionOS.
Thanks for the reply.
Yes, I am doing exactly the same as the example, including the RegisterPlugin.mm file. The same code works fine on iOS, but it does not work on VisionOS
And is RegisterPlugin.mm set up to build on visionOS in the import settings? Same goes for your library. If you put a NSLog call in RegisterPlugin.mm is it called?
Are you building for MR or VR? Can you try in a Windowed build?
More generally, why do you need UnityPluginLoad to be called? Can you call it manually from C#?
@mtschoen It looks like we’re hitting same issue as the original poster. I’ll add some more details since it’s fresh thread.
We’re also not getting a call to UnityPluginLoad. From iOS example (NativeRenderingPlugin) this call happens from Unity side and passes in IUnityInterfaces that are then used to get graphics device. It can not be be made from managed side from my understanding.
The call to shouldAttachRenderDelegate happens correctly in RegisterPlugin.mm
Changing to windowed mode in XR Plugin-management does not make it work.
Worth noting that other calls from RenderingPlugin.cpp do happen correctly. Eg GetRenderEventFunc (native unity side calls into that) and also managed P/Invoke also happens eg SetTimeFromUnity. But still without call to UnityPluginLoad rendering can’t happen.
As a side I also did build NativeRenderingPlugin for visionOS - without adding PolySpatial or Apple visionOS from XR Plug-in Management just to get it as close to iOS example as possible. That actually did work on Vision Pro and rendered as windowed app (and metal rendering part also did work showing triangle and ‘wavy’ plane).
So looks like it is possible to get that example to work on device but not with Poly Spatial / XR Plugin.
We’re quite blocked on this one and it’s preventing us from using Unity for wider migration, we’re really keen to get past though this one though!
Unity 2022.3.21, Polyspatial 1.1.4
Hope that’s enough details to get you guys going - please let me know if there’s any more details that could be helpful.
Hey, just running into the same problem here… therefore BUMP
is there any solution available for this yet?
Ok, I found the problem - it is the “standard” name “UnityPluginLoad”. The VisionOS Library exports the same function, and that means that there are 2 (and probably even more) functions that have the same name. The way to fix it is:
- in RegisterRenderPlugin.mm declare
UnityPluginLoadMYLIB
UnityPluginUnloadMYLIB
and also bind those with
UnityRegisterRenderingPluginV5(&UnityPluginLoadMYLIB, &UnityPluginUnloadMYLIB)
- on the C++ side of things, just rename functions to UnityPluginLoadMYLIB and UnityPluginUnloadMYLIB.
The plugin will load as it does on iOS and others.
Ah! Thanks for sharing the fix. This is probably something we can fix in the plugin as well so that people don’t run into this so easily.
You just have to be careful about doing it right on the C++ side to not break it for the Editor. The RegisterRenderPlugin.mm is just used on iOS and VisionOS. If you change the name for all, Editor and all others will not work. Therefore my fix looks somewhat like this
#if UNITY_VISIONOS || UNITY_IOS
extern "C" void DECLDIR UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API UnityPluginUnloadMYLIB()
#else
extern "C" void DECLDIR UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API UnityPluginUnload()
#endif
and the same for the Load. Note that I added the UNITY_VISIONOS flag myself…