-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Any tips for optimizing? #23
Comments
If your camera does not have an overview of the whole map, you could try to deactivate the cars when they are not visible by your main camera. I never used it but maybe these functions could help: https://docs.unity3d.com/ScriptReference/MonoBehaviour.OnBecameVisible.html So inside OnBecameVisible you can set the object to .SetActive(true) and OnBecameInvisible to .SetActive(false) |
But if i deactivate a car it stops and loses all the motion, and when i activate it again it just starts driving from 0 km/h. |
Just found out I can't use those OnBecameVisible/OnBecameInvisible stuff for settings the activeness of an object since when some object gets deactivated it can never get activated again by OnBecameVisible. Well I could use them for enabling/disabling renderers but i think Unity already stops rendering objects when they are not visible on camera. |
I think what i need at the moment is being able to spawn cars with some motion, I mean not from 0 km/h. I want them to spawn with a specific velocity. So i can just spawn them anywhere, like in the middle of the road when player comes close to spawnpoints, and destroy the cars that are far from player. I think that will be good for performance, do you know how can i do it? |
Yes that would be a good solution as well! |
Well i increased it a lot, but the difference is very small Also what does stuff like Steering Lerp and Brake Torque do? |
Turns out that these were happening because of my Rigidbody Drag settings, And i don't think there is any option other than increasing the drag values, these cars just cant turn when they are going fast |
I found a way to spawn the car with velocity, and implemented object pooling. |
Glad you found a way to spawn the car with velocity - just curious, how did you do it? To spawn cars on your waypoint system you can do as below. Basically, you get all the segments and then for each segment, iterate through all the waypoints' positions. Then it's easy, you can just calculate a new point (where you will spawn you car) which will be in between waypoint X and waypoint Y at a certain distance D from waypoint X.
|
I did it basically like this
And for the spawnpoints, i found a way to put them on Traffic System Gizmos, i took the code from TrafficSystemGizmos.cs and edited for my purpose.
But thanks anyway for the script |
Now im working on enabling the spawnpoints only when player is close to them, and destroy traffic cars when they are far behind player. |
I did everything i wanted. Now it never gets under 100 fps with roads full of traffic. Before all these optimizing stuff it were starting with ~40 fps then slowly decreasing untill like 10-15 fps |
This isn't really an issue, the traffic system works perfectly but the maps I'm using it on are huge, so it has very bad performance.
Do you have any suggestions for optimizing the system on big maps? I'm new to the scripting stuff on Unity so I don't know much.
The text was updated successfully, but these errors were encountered: