Whats the Issue
I am currently developing a train game, which involves multiple trains moving using VectorForce. Currently, each train has about 450 Parts.
As the number of trains set in motion increases, there is a increase obvious presence of lag. The trains movement is no longer smooth [More choppy] And it begins to slowdown in general
What I have done
I’ve tried to reduce the part count as much as possible by combining or unioning multiple parts into single meshes and deleting unnecessary ones whenever I could. After optimization, each train consists of around 450+ parts. I’ve also set CanCollide to false for most of the parts in the train.
-Yes i have searched through devForums for solutions
What I need help with
If there are more ways to reduce lag, do share them. I will implement them
If you decide to make your train system use Tweens, Bezier curves, or other mathematical functions for position, hit me up, I can explain a bunch of stuff
another interesting thing I’ve found recently is that, putting a humanoid inside a model with a bunch of welded together parts improves the performance by like 2x (BulkMoveTo() and other things become faster). Humanoids have an optimization in place where some things (dunno what exactly) is precalculated (and recalculated when the humanoid’s model changes, see updateInvalidatedFastClusters)
I don’t know if the performance improvement I saw also applies to objects with physics simulations, but it’s fairly easy to test it
I have a question then. When I Enable Streaming, how would I detect when a train is rendered to the client, so I can add all the visual props to the client.
As per your suggestion, would it be something like this:
Train [SimpleVersion] is loaded into client when its within specified range
I render the remaining Visual props to it when Train [SimpleVersion] is rendered
I would not have to remove the visual props, right? As when the train leaves the player’s “Area”, it gets streamed out anyways
Future Noob tells a great start. However I would like to add some stuff:
When we are talking about moving objects of any variety, simplicity is key. Keep unions simple and don’t add more detail than is necessary to achieve the desired effect. If something can be a texture rather than a physical part, do so.
Keep all effects and other stuff to a minimum. If your rail stock has a ton of audio effects, it may cause issues when playing at motion as audios can and do have to work with physics and the more there are, the more calculations that need to be made.
In addition to nocolliding the physical parts, turn off touch and query and even make the objects massless where you can. This cuts down on the ammount the platform has to factor when moving the assets.
Avoid using rolling wheels unless necessary, say for if its a steam locomotive. Also keep your articulation and other moving points (such as running gear and more) to a minimum as well.
As for your issue with Streaming Enabled: It shouldn’t be an issue. If this is a multiplayer game I would recommend not doing a local and server split vehicle and just keep the thing all server aside from the local control console (UI) as that is a lot of complication that is not needed. However for single player, the act of getting that to work will ensure it works well for you. Just limit that function to the train the player is controlling only and make other trains on the game basically ghosts physics wise.
Do also note, vector while simple isn’t always going to be ideal for a train simulation. Vector can be very finicky so if you need there are off-the-shelf traction based train platforms available. I can link you to one if you want.