Racast causes a lot if lag when i increase the part count above 15k

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    Fire a simple raycast without lag spikes

  2. What is the issue? Include screenshots / videos if possible!

when i add parts into the game , each time i start firing a raycast the game freezes for a sec
3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I tried changing the parts to non collidable disable the canQuery bool, anchoring them and still , it seems the raycast founds a way to include those parts into the method, i also use ignoreDescendants of the parts that i want to use which are rlly few…

Im firing a raycast every 0.25 sec , the lag spike happens only when i increase the partcount above 15000

Very little info to go off of, how long is this raycast?

1 Like

30 studs and 100
What amazes me is that it works perfectly with lower part counts…

i have another raycast that fires at 100 lenght every 0.25 secs but still doesnt explain why if i increase the part count the raycast starts to freeze the game…

I also made sure i didnt have any code iterating trough the whole workspace, i came to the conclusion is the raycast thanks to the script profiler

1 Like

I’ll give it a test myself later, one thing that’s notable though is that you are putting a task wait inside of a heartbeat. This doesn’t make sense because heartbeats get called every frame, so you’re not doing a raycast every 0.25 seconds, you’re doing it every frame, but delaying it first.

It’s not a great idea.

See every call of the function as it’s own independant one, because that’s essentially what it is. You’re connected to the Heartbeat, which means everytime the heartbeat happens, this function gets executed anew. The wait function doesn’t block the next call.

It’s not whats causing your issue, but you should fix it.

Yeah i noticed it and already changed for a while loop, it didnt make any difference tho :frowning:

I just tested it, and I couldn’t reproduce your issue at all. Created over 15000 parts, and did raycasts of random lengths every frame. No issue at all.

Unless you have anything else, I’d wager it’s just a processing issue and that your computer can’t handle it. Oh yeah, and you also shouldn’t use pcalls like that, just check for potential errors before you do the action instead of wrapping it up in a pcall.

Yea i also tried to reproduce it on an empty baseplate with 40k partd and couldnt found any issues, what i found is that there is a hugh renderjob block

Idk what does it mean

When you start getting in to high part counts, I find optimisations like removing Cast Shadow, disable CanCollide and CanTouch from purely simple scenic parts can make a huge difference to performance.

Just fixed it, it turns out i had a for loop iterating trough 5000 parts and firing raycasts lmao…

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.