How do I connect my Unity3d Model to my WPILib Code for FRCJava?

I want to simulate my FRC robot code in Unity3d. For this, I watched the video by Bill Kinahan on Youtube and was able to make the Unity3d Model. But I am having trouble getting to run and connect my Java code to it.

Link to Youtube Video: FRC Chassis Build Demo in Unity - YouTube

Please I have been trying everything. Since I have no prior experience with Websockets I don’t know how to actually use it nor do I know where to include it in the code. Any kind of help will be much appreciated. Thank You

1 Like

I’ve not used this, but from the README it sounds like the websocket pieces on the Unity side are already written for you. https://github.com/kinahawi/FRC-2021-Starter-Project

This step is the only thing you have to do on the robot code side to make Websockets work:

  1. Make sure the Websocket server based simulation option is available by uncommenting the appropriate line:
   simulation wpi.deps.sim.ws_server(wpi.platforms.desktop, false)

The file this is in is build.gradle.

1 Like

Hello, Thank You for the reply. However, I tried the solution earlier too. The problem is no such line exists in my wpilib gradle.build file and when I try to add such a line it gives an error.

I am using the 2022 version of WPILib with VScode and it seems that the file exists in an older version. Should I downgrade all my libraries to an older version(2019 or 2020 maybe)? I was hesitant to do that since all my code uses the newer library versions and dependencies.

For 2022, you need to add the following line:

wpi.sim.addWebsocketsServer().defaultEnabled = true
2 Likes

Thank You SO MUCH!!.. I tried your Solution and it worked for me. Thank You