Version 4 (modified by edy, 13 years ago) (diff) |
---|
Performance and optimization
I care about the objects being passed as reference to the functions in order to avoid copying objects. Feel free to check out the main scripts (CarMain, CarControl, CarWheel, and CarWheelFriction) and please let me know if you find something that could be optimized.
But there are operations that require entire objects to be created and deleted and cannot be optimized (or I don't know how to do it). Skidmarks, SkidSmoke (both controlled from CarVisuals) and CarDamage are the top memory wasters.
- Deforming the mesh in CarDamage requires to create a temporal copy of the entire vertex array of the 3D model, modify the copy, then reassign it to the Mesh Filter. Deforming the collider requires an entire temporal mesh (vertices + triangles) to be created and disposed.
- The Skidmarks are generated as a single mesh containing all the visible skidmarks for the scene (Hierarchy: World > Skidmarks). Each time a new skidmark is generated, the entire mesh is disposed and re-generated. Note that this is the skidmarks script from the Unity's Car Tutorial with a few minor adjustments. You can adjust the maximum mesh size for the skidmarks with the property MaxMarks.
- The smoke is just a particle emmiter (Hierarchy: World > Skidmarks > SkidSmoke), so it's up to Unity's particle system. Particles are generated and disposed as they go through their life cycle. You can adjust the number of particles with the properties MinEmission and MaxEmission, and their duration in seconds with MinEnery and MaxEnergy.
CarVisuals offers two flags disableRaycast and disableWheelVisuals which can be used on vehicles parked, computer-controlled, or outside the visual range. Note that disableWheelVisuals also affects the audio, as it depends on wheel's rotation rate.
Optimizing the friction curves
CarControl has a property optimized which controls the respective optimized properties at each CarWheel.
- Keep optimized DISABLED for fine-tuning the friction curves in real-time at CarControl (ForwardWheelFriction and SidewaysWheelFriction). The curve's internal parameters are recalculated on each cycle (FixedUpdate) allowing real-time modifications from the editor.
- ENABLE optimized for releasing the project, or when the friction curves don't require further modifications. The internal parameters are calculated once on start and then reused.
GUI objects
CarMain displays the vehicle's dashboard. You can disable it by setting the property guiEnabled to false.
CameraControl references the GUITexture objects used for the vehicle's mirrors. Set showMirrors to false for disabling all processing regarding the mirrors. You could also delete the GUITexture objects (children of MAIN), the mirror cameras (actually available at the Bus only), and the RenderTexture assets where the mirrors are rendered (located at Assets \ EdyVehiclePhysics \ GUI).
CarTelemetry displays the vehicle's internal data. It's used for development and fine-tuning with no typical usage in games. Easily disabled with Enabled = false.
CarDamage may display a small label when the vehicle is being repaired. Disabled with showRepairingLabel = false.