• Godot Help
  • How do I setup OpenXR in VisualScript (Godot 4 Alpha 12)

Hey everyone!

New person to game dev and GODOT. I did try to get this riddle solved over on Reddit with no luck so I'm going to be reposting here:

I'm wondering how do I setup OpenXR in VisualScript. Currently I've got the game to load up and track the HMD (Valve Index), but it doesn't output anything other then solid grey to the HMD and not what the game is exactly outputting. I've been banging my head against the walls for 5ish hours to get to this point and I'm at a stalemate. In the game window there is a 512x512 grey box on the top left of the screen where the "SubViewportContainer" is situated.

I realise version 4.0 is still in development and is considerably buggy/unstable compared to 3.4. My reasoning is that by the time this experience is even in a playable experience Godot 4 will be truly out, and I wanted some luxuries such as Vulkan.

I can never get my head around traditional coding and these node-based alternatives (such as C.O.F.F.E.E or Blueprints) I can better understand. Obviously I'm still learning the quarks of the engine.

What I've done so far:

  • Scrapped my original messy VisualScript with one more strictly following Godot's GDScript example.
  • Tried to stretch SubViewportContainer
  • Added a material to SubViewportContainer.
  • Tried to VisualScript-ise various GDScript solutions. (Including segments of Durials' VRScript to detect the RID of the viewport and camera as seen in the second screenshot)


I've ended up corrupting my VisualScript file (since GODOT 4 is currently in Alpha, that sort of stuff is expected) by fiddling around with it so much - I'm hoping one of you more seasoned developers can point me in the right direction.

Thank you in advance.

  • Hey! So I managed to get the video to output to the Index finally and the thing the problem was actually the SubViewport - apparently it's not needed with GODOT 4, where in 3.x you did (or the 3.x equivalent)... I'm too afraid to mess around with it as it is working... So I'm going to close this down.

    Thank you to everyone who helped! =)

I'm not really sure, since I haven't worked with VR in a bit (since I switched to Linux). However, VisualScript is almost a 1:1 mapping to GDScript, so I doubt there is any problem with it working. However, I'm not sure if your code is correct, and also Godot 4.0 is alpha, so there could be bugs. But in theory it should work.

    cybereality

    cybereality However, I'm not sure if your code is correct

    That's what I think - I'm not using the correct node or have wired it up the right way to give the desired outcome. I just need to know what node in question doesn't belong here.

    cybereality Godot 4.0 is alpha, so there could be bugs.

    I'm aware GODOT 4 will be is going to be on the buggy side, which is probably how the VisualScript got corrupted after a while of continuous fiddling. ^^"

    Quick update. I have remade the VisualScript, this time using a different "use_xr" node and it still isn't working. I'm not entirely sure what node is causing the problem as the aforementioned documentation is for GODOT 3.1 using "ARVR" commands while 4.0 uses "XR" style commands, so that is causing some additional confusion.

    Regardless, it still isn't working. The black box in the game window is the SubViewport-related nodes with the "SubViewport" specifically having transparancy enabled to see if that would fix it, but it only shows in the headset as solid black instead of solid grey; so it isn't much better.

    As cybereality said - this is most likely caused by me using the wrong nodes or wiring the tree up incorrectly. But with the documentation talking about ARVR instead of XR - it's hard to say from inexperience who the culprit is from my point of view... ^^"

    I can maybe try it tomorrow. I do have some headsets, but they don't work on Linux. Though I have a Windows 11 machine I use for testing that should work. I just haven't set it up. Maybe I'll have time later this week.

      cybereality
      Fair enough! I'm going to temporally shelve this until you have the opportunity to try this unique problem out yourself. I wish you nothing but luck! =)

      Thought I'd try to do a similar thing in Godot 3.4 to see if it was possible. But the exposed ARVR nodes in VisualScript is worse then the XR variables in 4.0... So that fell apart on figuring out how to do it in GODOT 4 quickly... ^^"

      Have you considered writing it in GDScript just to see if it works? If it does, it would be easier to port to VisualScript once you have a working demo.

        cybereality

        cybereality Have you considered writing it in GDScript just to see if it works? If it does, it would be easier to port to VisualScript once you have a working demo.

        Indeed I have, and even tried the latest code from the Github page. However the "wki" linked on the GODOT 4 branch still links to the GODOT 3 variant and such I have encountered the following problems:

        • If I extend "viewport" it complains it doesn't exist
          • If I use SubViewport then it say's it cannot use the Node3D as a base.
          • Changed it to Node3D as it is similar to the OG wiki's mention of "Spatial".
        • It says the interface "_ready()" doesn't exist, so I changed it to "start_vr"
        • Not exactly a problem but I had to change "ARVRServer" to "XRServer" because "ARVRServer" no longer exists.
          • By the same logic I changed get_viewport to "xr" instead of "arvr"

        With that said and done, it's still doing the exact same thing as with VisualScript with a grey box on the top left of the screen where the container is in "2D" view and showing a solid grey on the Index... And I'm still don't know what's causing it. Here is the code as it currently stands:

        Hope this helps

          UnusualCore Quick Update -
          I somehow randomly found a demo for GODOT 4 VR with the correct code which I more or less copied and pasted into. Still not working and it's starting to make me wonder if I setup the "info_player_sp" instance incorrectly because surely it shou;d be working from that script.

          This is what the looks like:

          Interestingly it didn't complain about the interface "_ready()" with this script then the one that I made for whatever reason... At my lunch break I'll try to upload the project without the imported models/textures for you to take a poke around at to see if everything is setup correctly because I feel I've done something wrong and it's right under my nose... ^^"

          As promised here is the project minus the models/textures specific to it, you might get an error saying it can't find stuff relating to the testbed model, but you should be able to cancel it.

          Just go through and make sure everything is checked that's suppose to as something is clearly not right when even GDScript doesn't make the Index output the game while it is able to track the movements of the Index.

          GODOT4_VR_broken.zip

          Hope this helps!

          Hey! So I managed to get the video to output to the Index finally and the thing the problem was actually the SubViewport - apparently it's not needed with GODOT 4, where in 3.x you did (or the 3.x equivalent)... I'm too afraid to mess around with it as it is working... So I'm going to close this down.

          Thank you to everyone who helped! =)

          Okay cool. Sorry, I've just been busy and haven't had time to test.