Dim passthrough at runtime

Is it possible to dim the passthrough through Unity using SurroundingsEffect? SurroundingsEffect | Apple Developer Documentation

We would like to set various levels of passthrough at different points in the game. Similar how Mindfulness makes the passthrough darker when the orbs expand and surround you in full space.

1 Like

I can dim the passthrough directly in Xcode by adding .preferredSurroundingsEffect(.systemDark) but just wanted to see if there was a way to set this directly in Unity?

Not at this time, no. You can file a bug report requesting this support and paste the ID here and we’ll look into this for a future release.

1 Like

@Jaynesh I was unaware this was possible to specify on the Xcode side! I want to test this for my fully immersive app, but am unable to find where to apply your code snippet. I’m pretty new to Xcode/Swift, but in the past, I was able to do things like hide the passthrough limbs by appending to ImmersiveSpace definition in UnityMain.swift. Can you give a little more detail on where to apply this? Xcode seems to hint that it has to do with the “View”… Thanks!

@puddle_mike Yes ofcourse!

In Xcode, look for the UnityVisionOSSettings.swift file and modify it like this

        ImmersiveSpace(id: "Unbounded", for: UUID.self) { uuid in
            PolySpatialContentViewWrapper()
                .environment(\.pslWindow, PolySpatialWindow(uuid.wrappedValue, "Unbounded", .init(1.000, 1.000, 1.000)))
                .preferredSurroundingsEffect(.systemDark)
        } defaultValue: { UUID() }

Right now it seems to only allow you set it to .systemDark which is tied to a specific value, there doesn’t seem to be a way to set your values.

Thanks for the snippet @Jaynesh! It looks like UnityVisionOSSettings.swift doesn’t exist in Fully Immersive apps (i.e that don’t use PolySpatial). We have a UnityMain.swift, but I don’t see any way to access the “ViewWrapper” within its definition of an ImmersiveSpace. I’m a little outta my element here, but will keep digging. Here’s the relevant code from UnityMain.swift if anyone has any suggestions on what to try:

  var body: some Scene {
        WindowGroup {
            Text("Loading").onAppear() {
                Task { @MainActor in
                    await openImmersiveSpace(id: "CompositorSpace")
                }
                // TODO: doesn't work?
                self.dismiss()
            }
        }
        
        ImmersiveSpace(id: "CompositorSpace") {
            
            let _ = UnityLibrary.GetInstance()
            let unityClass = NSClassFromString("UnityVisionOS") as? NSObject.Type

For anyone else following this, we have another thread on this specifically about fully immersive apps here:
https://discussions.unity.com/t/tinting-lighting-of-passthrough-limbs/307031

I’m still stuck on this. Anyone get the passthrough hands darkened in a fully immersive app? Or is it just not possible to specify like it is for mixed reality apps?