How to add native plugin code to a visionOS build?

We have a couple of iOS plugins that might also be useful on visionOS. Some of them, including a custom UnityAppController, are placed as .mm and .h files under /Plugins/iOS and thus being copied to the Xcode project folder /Library/Plugins on build.

I tried to use the same approach for visionOS, but it doesn’t seem to work. First, I tried to just add the “Vision OS” platform flag to these files, then I additionally placed them in a “VisionOS” or “visionOS” folder. But none of these attempts resulted in the files being copied to the Xcode project.

Is this approach even supported?

1 Like

We’ve successfully used our custom CloudKit and GameKit plugins that were written for iOS with very minimal changes. One thing we do that you might be missing is at build time we conditionally include native plugins based on define symbols, and that runs .mm and .h etc files through a step that calls SetIncludeInBuildDelegate on the plugin importer:

var importer = AssetImporter.GetAtPath(pathToSource) as PluginImporter;
if (importer != null && importer.isNativePlugin) {
    importer.SetIncludeInBuildDelegate(includeInBuildDelegate);
}

Thanks, joe. But we’re not using this approach. I learned in another thread, that the problem might be related to the CPU architecture not being set in the meta files. But even setting this prop did not work for me.

Hi, in my case the native .mm files are also not copied to the xCode project (Unity 2022.3.17) when building for VisionPro. I need to copy them manfully into xCode project.

Any updates on how we can include native libraries for Apple Vision OS in Unity?

I managed to do this by just adding visionOS as the target for the library. It was then automatically copied to the build.

@waldgeist - it works fine for libraries, but I can’t get it to work for plain .mm and .h files. Did you manage to get that working?

I’m not sure if I did this. I finally gave up with Unity on visionOS and went native. There were too many limitations, and the new pricing model was also not in Unity’s favor.

Ok, thanks for the quick response. And sorry to hear that. I know from the forum that you did put a lot of effort into it. And I agree, it has been (and is) a bumpy ride.

No worries, our app aready went live on the visionOS app store :slight_smile:

1 Like