-
Notifications
You must be signed in to change notification settings - Fork 12
Description
Is there an existing issue for this?
- I have searched the existing issues
Unity version
Unity 6000.0 LTS
Common issues
- I have checked the common issues
Flutter version
3.32.4
Description
I kept getting some build errors related to OnUnityMessage and OnUnitySceneLoaded.
Im not a very proficient developer but I troubleshot this for about 7 hours using chatGPT with little success and going down some fruitless rabbit holes. Finally, it suggested to add the following to this file "ios/.symlinks/plugins/flutter_embed_unity_2022_3_ios/ios/Classes/Messaging/SendToFlutter.swift" and it worked!! (ive only tried on iOS so far).
code to add:
(insert on line 15)
// These two C-callable shims are required by the Flutter embedder. Unity links
// against them when sending generic messages and scene‑loaded notifications.
@cdecl("OnUnityMessage")
public func onUnityMessage( objPtr: UnsafePointer?,
_ jsonPtr: UnsafePointer?) {
// The plugin only cares about the JSON payload coming from Unity
guard let jsonPtr = jsonPtr else { return }
let json = String(cString: jsonPtr)
SendToFlutter.sendToFlutter(json)
}
@cdecl("OnUnitySceneLoaded")
public func onUnitySceneLoaded( namePtr: UnsafePointer?,
_ buildIndex: Int32,
_ isLoaded: Bool,
_ isValid: Bool) {
// Pack the scene‑loaded event into a JSON blob so Flutter can switch UI, etc.
let sceneName = namePtr != nil ? String(cString: namePtr!) : ""
let payload: [String: Any] = [
"sceneName": sceneName,
"buildIndex": buildIndex,
"isLoaded": isLoaded,
"isValid": isValid
]
if let data = try? JSONSerialization.data(withJSONObject: payload),
let json = String(data: data, encoding: .utf8) {
SendToFlutter.sendToFlutter(json)
}
}
ChatGPT's explanation:
I added the two missing C-callable shims (OnUnityMessage and OnUnitySceneLoaded) to SendToFlutter.swift. They forward Unity messages and scene-loaded events to Flutter through the existing SendToFlutter helper.
Rebuild the iOS target and those undefined-symbol linker errors should disappear.
Minimum reproducible example (MRE)
No response
What platforms are you seeing the problem on?
No response
Devices
iphone13
Anything else?
No response