Grid Setup, Netcode Ghosts
Lecture Summary: Grid Setup and Netcode Ghosts
In this lecture, we set up the grid for our game and learned how to handle clickable grid positions using Unity DOTS and Netcode for Entities. Along the way, we explored some of the challenges and quirks of working with physics and networking in DOTS.
Since DOTS doesn’t natively support 2D sprites, we used flat quad meshes with unlit materials to simulate a 2D visual style. We set up the grid layout, added box colliders to each grid position, and made them into prefabs.
To enable clicks, we created a GridPositionClickClientSystem
that listens for mouse inputs and performs raycasts to detect clicks on the grid positions. However, physics raycasting didn’t work out of the box due to changes introduced by the Netcode for Entities package. To solve this, we learned about Ghosts—networked objects that synchronize their state across clients and servers. By adding the Ghost Authoring
component to our grid positions and marking the connection as "InGame," we ensured the grid objects were properly spawned and detected. But clicks still didn't work.
We also had to add a NetCodePhysicsConfig
component to the scene and set the PhysicsRunMode to "Or Any Physics Entities" to make raycasting work correctly. After testing and debugging, everything finally worked smoothly, and we could detect clicks on the grid positions.
Finally, we added a GridPosition
component to store the X and Y coordinates of each grid position, allowing us to log where the user clicked. This setup is now ready for game logic implementation, which we’ll handle in the next lecture!
11 comments