Reduce lag caused by lots of trees?

so i want to have quite a bit of trees in my game, but the problem is that theyre causing a lot of lag. the trees im currently using are really simple, just some decals put on a cylinder and yet its still laggy as hell.

4 Likes

I would suggest custom rendering, basically a script that essentially creates an array of every tree in the game, and constantly loops through to check the distance of that tree to the player and based on that changes the parent to serverstorage, just an idea. Also, make sure to take advantage of Roblox’s built in rendering.

6 Likes

That’s probably a bad idea with numerous trees in-game. The more objects you have to loop through, your code will run slower or consume more processing power relative to the amount of objects. I suggest using the built-in Roblox rendering program.

1 Like

yeah there are like 2500 trees so it could be a problem. streaming always creates problems tho, like it just breaks some of my scripts because everything is unloaded and its just really annoying

2500 trees? Do you really, really need that many trees loaded at the same time on your map?

2 Likes

That is not true, if written correctly it would be fine, now personally I wouldn’t use a loop, maybe an event, say every time the player moves run the function, either way, there are ways to implement this and uphold good game performance.

What you’ve just said is nonsense. With 2500 trees the code will either lag the game at certain intervals (at the discretion of the programmer setting those loop intervals for it), or it will deload objects very slowly. Stop spreading bad practices.

well yea the map is quite big

I have literally ran code that loops several thousands of times, if you bind it to renderstepped and create an array and a check interval you could essentially “loop” through the array and not hurt performance at all. I think its nieve for you to sit here and say there is no way to implement this when it has been done and is literally done in every major game out there, how do you think GTA V renders there map? you think everything is just loaded in? Now yes, a loop is a bad idea if we are talking about thousands of instances, but you can create a “loop” that doesnt actually use a loop function and will not hault thread.

2 Likes

An alternative solution to this could use the modified King’s solution. You could implement a system which would every certain interval search the player’s area for simple part objects called ‘tree spots’. If it finds them, actual trees then replace those tree spots. I am unsure if you could leave those trees as is and only change their transparency value to achieve peak performance, or if you could load and deload those trees dynamically into folders. Experimentation is needed.

2 Likes

Show me your game that has implemented the very code you spoke of. If it even exists, it probably does very few calculations and leaves a lot of processing space for code of your design. However, it will most likely not work on games that are more complex than simple obbies, gain +1 X every 1 second simulators, etc.

1 Like

i just did that and its definetly gotten way better, but i feel like it just looks weird with no trees in the distance


i want it to look more like this

with more trees visible in the background

2 Likes

And you did what exactly, did you make a script that determines which trees to load from a 2500 tree list at a single time, or is it looped to continually update for player’s position, or what other method?

right now i just made a simple script that loops through all the trees and loads and unloads depending on the distance

In-game, how many FPS have you saved with it, and can you tell me how much expensive that script is according to script performance tab?

1 Like

Try custom rendering, the further away the player is from them, they get lower quality.

I swear im not jealous of you having 200fps when I run on 30 by average :sob:

1 Like

fps wise its lookin real good, my game is running at maybe like 180-200 fps when looking at the sky/ground and 130-140 when looking at the trees, but performance wise, the script definetly stands out
image
guess ill have to try something different

Almost like I said it would atleast help, hmm. thats crazy. Lol.

1 Like

My guess is too many decals and overdraw.

As far as I know, Roblox renders transparent objects and decals differently in a way that is way more expensive than just rendering a solid model.

You can try using only mesh-based trees instead where all the leafs are also just a single mesh.
This should already optimize a lot.

Worst case scenario you’re gonna have to avoid using decals all together and resort to using solid/non-seethrough models only.

I suggest making all leafs just a single model so every tree only needs to use 1 single decal for all the leafs.

1 Like

yeah but i feel like that wouldnt look as cool. thats like the final option. its gotta be possible though since project delta has so many trees and runs so well (pic above)