Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
ECS Network Racing Sample - Improvements & Documentation
This document provides a comprehensive overview of the improvements made to the ECS Network Racing Sample project, including bug fixes and new features.
Table of Contents
Bug Fixes
1. Vehicle Velocity Threshold Configurable
File:
Assets/Scripts/Gameplay/Vehicle/VehicleControlSystems.cs
andAssets/Scripts/Components/Wheel.cs
Issue:
The
WheelRaycastJob
contained a hardcoded velocity check that would skip raycast operations if the velocity exceeded 50 units. This value was arbitrary and not configurable, which could cause unexpected behavior at high speeds for different vehicle types.Fix:
MaxSafeVelocity
property to theWheel
componentVehicleAuthoring
class with a default value of 50fBenefits:
2. Suspension Physics Bug Fixed
File:
Assets/Scripts/Gameplay/Vehicle/VehicleControlSystems.cs
Issue:
In the
SuspensionForceJob
, there was an incorrect use ofmath.clamp
with parameters in the wrong order. The function was called withmath.clamp(10, -10, springVelocity)
which had min greater than max, causing incorrect clamping behavior of spring velocity.Fix:
math.clamp(springVelocity, -10, 10)
Benefits:
3. Network Connection Error Handling
File:
Assets/Scripts/Gameplay/Connection/ServerConnectionUtils.cs
Issue:
The network connection code lacked proper error handling for invalid IP addresses or failed connections. Additionally, the
DestroyLocalSimulationWorld
method could potentially cause issues by disposing of worlds without checking if it was safe to do so.Fix:
LastConnectionError
string to store error messagesDestroyLocalSimulationWorld
with a saferSafeDestroyLocalSimulationWorld
method that includes exception handlingworld.IsCreated
before disposingBenefits:
4. Input Handling Improvement
File:
Assets/Scripts/Gameplay/Vehicle/VehicleInputSystem.cs
Issue:
The
CarInputSystem
was adding inputs from multiple sources together, which could lead to unintended magnitudes if multiple input methods were active simultaneously. This made vehicle control unpredictable when using multiple input devices.Fix:
UpdateMaxAbsoluteValue
to simplify this processBenefits:
5. Configurable Network Smoothing
File:
Assets/Scripts/Gameplay/Vehicle/VehicleSmoothingSystem.cs
Issue:
The
VehicleSmoothingSystem
used a hardcoded smoothing factor of 0.7f for all smoothing operations. This value wasn't configurable and might not be optimal for all network conditions or game feel requirements.Fix:
SmoothingConfig
component to store smoothing parametersBenefits:
6. SystemAPI Access in Burst-Compiled Methods
File:
Assets/Scripts/Gameplay/Vehicle/VehicleSmoothingSystem.cs
Issue:
The system was trying to use
GetComponentLookup
inside Burst-compiled methods without having a reference to the SystemState, causing a SGSG0002 compiler error.Fix:
SharedStatic<float>
field to store the smoothing factorOnUpdate
method to update this static value from the component dataBenefits:
7. C# Language Version Compatibility
File:
Assets/Scripts/Gameplay/Vehicle/VehicleSmoothingSystem.cs
Issue:
The code was using a parameterless struct constructor which is only available in C# 10.0 or later, but the project is using C# 9.0, causing a CS8773 compiler error.
Fix:
OnCreate
methodBenefits:
8. Vivox Service Null Reference Exception
File:
Assets/Scripts/Gameplay/UI/Vivox/MonoBehaviours/VivoxChannel.cs
Issue:
The
OnDestroy
method inVivoxChannel
was attempting to unsubscribe fromVivoxService.Instance
events without checking if the instance was null. Additionally, it was not unsubscribing from theLoggedOut
event that was subscribed to in theJoinLobbyChannel
method.Fix:
VivoxService.Instance
before unsubscribing from eventsLoggedOut
event that was missingBenefits:
Debug Logging System
A comprehensive debug and logging system for the ECS Network Racing Sample that provides:
Getting Started
RaceLoggerSetup
component to a GameObject in your main sceneRaceLoggerSettings
asset by right-clicking in the Project view and selectingCreate > Racing > Debug > Logger Settings
RaceLoggerSetup
componentLog Types
The logging system supports different types of logs with distinct colors:
Usage Examples
Basic Logging
Log Sections
To group related logs, you can create labeled sections:
Custom Colored Logs
You can use custom colors by specifying a hex color:
Configuration
The
RaceLoggerSettings
asset allows you to configure:Architecture
Core Components
Integration Points
The logging system integrates with:
Additional Features
Customization
You can extend the system by:
RaceLogger
RaceLoggerSettings
to include additional optionsSummary
These improvements address several core issues in the ECS Network Racing Sample, making it more robust, configurable, and maintainable. The focus has been on:
All changes were made with backward compatibility in mind and should integrate seamlessly with the existing codebase.