Hi, I am trying to do a few wonky things to accomplish something specific but simple.
I would like two way communcation between Unity and some Native SwiftUI views.
I can get SwiftUI Views rendering in tandem with Unity by injecting a Scene (that contains a window group) Reference into UnityPolySpatialApp, and manually opening it by name in the init method.
I then get to the point where there seems to be two options for passing messages to Unity from Swift.
- Using unityFrameWork.sendMessageToGO using a snippet like the following, and a Gameobject living in a loaded scene with the appropriately named monobehaviour / method.
static func sendMessageToUnity(message: String) {
let gameObjectName = "SwiftBridge"
let methodName = "ReceiveMessageFromNative"
let unityFrameworkInstance = UnityFramework.getInstance() // Get the UnityFramework instance
unityFrameworkInstance?.sendMessageToGO(
withName: gameObjectName,
functionName: methodName,
message: message
)
}
I get this buildtime error trying to run this. Undefined symbol: _OBJC_CLASS_$_UnityFramework
Is it not possible to call methods on UnityFramework from the Unity-VisionOS target? I am a bit naive when it comes to XCode project configuration
- The second option, which I will likely need to use for more complicated two-way communication is to use Native Plugins and call into objective-c from c# land.
I have an ultra simple class-pair that looks like this:
obj-c header:
#import <Foundation/Foundation.h>
@interface SwiftBridge : NSObject
+ (void)sendMessageToNative:(NSString *)message;
@end
obj-c class:
#import "SwiftBridge.h"
@implementation SwiftBridge
+ (void)sendMessageToNative:(NSString *)message {
NSLog(@"%@", message);
}
@end
c# wrapper:
using System.Runtime.InteropServices;
public static class SwiftBridge
{
[DllImport("__Internal")]
public static extern void sendMessageToNative(string message);
}
super simple monobehaviour calling said wrapper that lives in a scene.
using UnityEngine;
public class SwiftBridgeBehaviour : MonoBehaviour
{
private void Awake()
{
SwiftBridge.sendMessageToNative("Hello from Unity, Native Land!!!!");
}
}
This crashes immediately with this runtime error:
dyld[65510]: missing symbol called
Am I missing something with respect to setting up native plugins with VisionOS? It definitely makes it’s way into the build (see screenshot – it is in an ios directory, but I have tried Plugins/VisionOS directory etc…)
The third, painful, option seems to be using UAAL. I run into issues even going through the template’s readme for iOS w.r.t #importing UnityFramework/UnityFramework.h even after setting everything up to work with the simulator.
Even better would be if there was something pre-built that I can use as part of the PS Swift Wrapper to send messages back and forth. That is not the case, no?