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.csandAssets/Scripts/Components/Wheel.csIssue:
The
WheelRaycastJobcontained 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:
MaxSafeVelocityproperty to theWheelcomponentVehicleAuthoringclass with a default value of 50fBenefits:
2. Suspension Physics Bug Fixed
File:
Assets/Scripts/Gameplay/Vehicle/VehicleControlSystems.csIssue:
In the
SuspensionForceJob, there was an incorrect use ofmath.clampwith 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.csIssue:
The network connection code lacked proper error handling for invalid IP addresses or failed connections. Additionally, the
DestroyLocalSimulationWorldmethod could potentially cause issues by disposing of worlds without checking if it was safe to do so.Fix:
LastConnectionErrorstring to store error messagesDestroyLocalSimulationWorldwith a saferSafeDestroyLocalSimulationWorldmethod that includes exception handlingworld.IsCreatedbefore disposingBenefits:
4. Input Handling Improvement
File:
Assets/Scripts/Gameplay/Vehicle/VehicleInputSystem.csIssue:
The
CarInputSystemwas 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:
UpdateMaxAbsoluteValueto simplify this processBenefits:
5. Configurable Network Smoothing
File:
Assets/Scripts/Gameplay/Vehicle/VehicleSmoothingSystem.csIssue:
The
VehicleSmoothingSystemused 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:
SmoothingConfigcomponent to store smoothing parametersBenefits:
6. SystemAPI Access in Burst-Compiled Methods
File:
Assets/Scripts/Gameplay/Vehicle/VehicleSmoothingSystem.csIssue:
The system was trying to use
GetComponentLookupinside Burst-compiled methods without having a reference to the SystemState, causing a SGSG0002 compiler error.Fix:
SharedStatic<float>field to store the smoothing factorOnUpdatemethod to update this static value from the component dataBenefits:
7. C# Language Version Compatibility
File:
Assets/Scripts/Gameplay/Vehicle/VehicleSmoothingSystem.csIssue:
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:
OnCreatemethodBenefits:
8. Vivox Service Null Reference Exception
File:
Assets/Scripts/Gameplay/UI/Vivox/MonoBehaviours/VivoxChannel.csIssue:
The
OnDestroymethod inVivoxChannelwas attempting to unsubscribe fromVivoxService.Instanceevents without checking if the instance was null. Additionally, it was not unsubscribing from theLoggedOutevent that was subscribed to in theJoinLobbyChannelmethod.Fix:
VivoxService.Instancebefore unsubscribing from eventsLoggedOutevent that was missingBenefits:
Debug Logging System
A comprehensive debug and logging system for the ECS Network Racing Sample that provides:
Getting Started
RaceLoggerSetupcomponent to a GameObject in your main sceneRaceLoggerSettingsasset by right-clicking in the Project view and selectingCreate > Racing > Debug > Logger SettingsRaceLoggerSetupcomponentLog 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
RaceLoggerSettingsasset allows you to configure:Architecture
Core Components
Integration Points
The logging system integrates with:
Additional Features
Customization
You can extend the system by:
RaceLoggerRaceLoggerSettingsto 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.