How should I make a render distance?

I’ve seen someone make a render distance script, and Im wondering, how should I go about making this?

4 Likes

This is a good start:

2 Likes

I want to make a script render distance for parts, this is for the player. Not for me.

2 Likes

StreamingEnabled is the way to go, there’s no other ways. Just enable it, and there ya go!

4 Likes

This is not for the player, the link inside my link shows you how to enable streamed content and how to set the render distance of assets so that players see content loaded in at a defined distance range.

1 Like

It you want a basic system for render distance, just have a script, that gets a number (the render distance) and then loops through workspace. If parts position - cameras position > render distance then make the part invisible.

(This would be in StarterPlayerScripts)

local RenderDistance = 10

local Players = game:GetService('Players')
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local HumanoidRootPart = Character:WaitForChild('HumanoidRootPart')

while task.wait(1) do
	for i, v in pairs(workspace:GetDescendants()) do
		if v:IsA('Part') and (HumanoidRootPart.Position - v.Position).Magnitude > RenderDistance then
			v.Transparency = 1
		elseif v:IsA('Part') then
			v.Transparency = 0
		end
	end
end
6 Likes

This seems really easier, but could you explain it more?

Im a bit confused on what the difference of GetDescendants() and GetChildren, is, and I don’t understand the formula for this and magnitude works.

Maybe in game start insert everything on workspace to a local table and loop through that table.

https://developer.roblox.com/en-us/api-reference/function/Instance/GetDescendants
read this, it tells you everything
to summarize though
GetDescendants() gets the children of the model, and the children of the children
GetChildren() only gets the children of the object

Yep, detecting new child’s will solve this problem

1 Like

Like @TurtlesUnknown said, using :GetDescendants on the workspace is gonna be horrid for performance, additionally, setting a parts transparency is also not a good idea. If the part has a texture or decal assigned to it that will still render, and that creates massive issues when it comes to performance as decals and textures are more expensive on transparent objects. Additionally, this doesnt really fix much when it comes to performance as the part is still actually there. You would want to parent the part to something like ReplicatedStorage, but this can have bad effects on things like assemblies which will break the way that its physics would be rendered, de-syncing the physics of them entirely. Generally just use StreamingEnabled as it is a lot better and way way more performant than anything you can do inside the game. It even supports streaming meshes which creates fake imposter meshes in place of more complex models.

TLDR:
The best and most performant option is StreamingEnabled and any other method that you use will be massively more expensive.

1 Like

I still don’t understand how Im supposed to use streaming enabled for this, I read through the article that was sent, but I still can’t find a solution.

Simply enabling StreamingEnabled will cause it to work. Anything outside of StreamingTargetRadius will not be loaded to the player. If you use the Opportunistic option for StreamOutBehavior then any parts outside of the StreamingTargetRadius will be unloaded when the player leaves regardless of the amount of memory. Using LowMemory however (default method), will cause the game to stream out only when the client really needs it to.

1 Like

The roblox reference i sent you in the beginning is a service embedded in roblox, so it will be more performant than scripting it yourself. Just enable StreamingEnabled and set the distances you want things to appear in, and you’re done. It’s not difficult, just follow the steps outlined in the reference page and you are done in like a minute.

I actually havent had any issues using :GetDescendants before, and i actually get a better frame rate using it.

My method:
(130+ fps, very few and short fps drops)

The entire map loaded at once:
(46.1 fps)

Streaming Enabled:
(56.4 fps, max of 82 fps, but my game doesnt function)

Edit: I will be using StreamingEnabled now that i know what it is, and how to use to, but for that game, the script gets better performance, and still allows for the game to work.

3 Likes

You do have to change your scripts a bit to work with StreamingEnabled. This is outlined in the article. The issue is that while maybe this can work in this instance, from experience this generally doesn’t work well at all with bigger maps especially if they have a high LOD as the amount that the client will have to go through can grow exponentially. Additionally, StreamingEnabled allows you to dynamically load terrain, which is something you cannot do with :GetDescendants.

Also be sure that you implemented StreamingEnabled correctly. Were you using Opportunistic or LowMemory as the stream out behavior? If you were using Opportunistic it would fit properly to the behavior of your script above. It’s a bit more work but it can be a lot less unorthodox and will make development easier to handle as long as you keep the impacts in mind and use the correct methods to handle parts streaming in and out.

1 Like

I spent the last 15 minutes messing around, and looking at how to use StreamingEnabled, and the best performace i could get while still having the game load and work, was 51.5 fps, with the first cutscene taking around 2 seconds longer to play, you are right though, my scripts didnt have to be changed, however i already knew that.
Im not going to act like im smart, i was still probably using StreamingEnabled incorrectly, but considering what i have right now works well, im not going to bother switching over.

(And also, heres why StreamingEnabled is an issue for the cutscenes)


And in case your going to ask why i dont just move the cutscene closer to the start position, the reason is that the cutscene area is a playable section later in the game (Just with all the cutscene elements called out)

Also, the rendering script i made for the game runs every 2.5 seconds, just to cause as little frame drops as possible, while keeping the immersion. The script for my game also only effects a specific model too, and not every single part in workspace. (Plus i just modified it to not GetDecendants of workspace, and only GetDecendants of the specified models, the new script gets a max of 180 fps)

1 Like

To help with this in the future, you can do things like set the replication focus or use :RequestStreamAroundAsync to load a radius around the cutscene before the it plays. I do agree that it can increase load times however, and using a model aswell as only running every 2.5 seconds is definitely going to be better than doing something like binding it to heartbeat.
Apologies for the late response.

Instead of using GetDescentdant() for every frame, you can use descendant added to create a list and go from there and descendant removing to work with the list when an instance is terminated. This should optimize the use of GetDesc.

I made a similar system that also does this based on camera FOV that fires every time the camera moves. I wonder if setting transparency to 1 performs better than putting the objecting parent in replicated storage.

It’s been 5 months

I recommend you message @Chark_Proto, because a month old post doesn’t really need to be replied to.