Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Is there any way to preload Unions?

Asked by
d3lego 10
9 years ago

Hi there! I have a model with about 80-something unions in ReplicatedStorage that I need to load into Workspace at certain times. Thing is, it takes a good 5 seconds to fully load everything the first time.

I'm trying to figure out a method of preloading the unions inside of the model before it's needed by the client.

I've tried two different ways of preloading unions. Keeping the model in the Workspace with all Parts and Unions with a Transparency of 1 was one idea. But it does not appear that ROBLOX renders objects when they're invisible, so the unions never got loaded.

And then there's the method I'm using currently. It moves the model into the Workspace and then back to where it started in ReplicatedStorage. The wait(.25) is required. Without it, it seems that the parenting happens so fast that ROBLOX doesn't render the model to the client, so asset loading doesn't happen.

local model = game.ReplicatedStorage.UnionedModel

local function preloadUnions()
  model.Parent = workspace
  wait(.25)
  model.Parent = game.ReplicatedStorage
end

preloadUnions()

-- 60 is arbitrary. The model has more than 60 unions to load, so if the queue
-- size gets that big we can assume that the model is being loaded.
if game.ContentProvider.RequestQueueSize > 60 then
  print("Preloading model")
end

-- After waiting a few seconds, the model is moved back to the Workspace. All
-- unions are fully loaded.
wait(3)
model.Parent = workspace

The only problem with this method is that it's inconsistent. It works very often when I run a solo test, but when I start up a server with a couple players, it will occasionally not load for one or more of the players. Using an arbitrary wait time is also not ideal, and could be the cause of the inconsistencies. An easy solution would be to increase the wait time, but I want to minimize how long that the model is rendered.

I've tried using WaitForChild to make sure that the model is in Workspace before moving it, but it still reparents before it can render. Then I tried a combination of WaitForChild and Heartbeat, which is still inconsistent.


-- WaitForChild local function preloadUnions() model.Parent = workspace -- Still reparents faster than it can render workspace:WaitForChild(model.Name) model.Parent = game.ReplicatedStorage end -- WaitForChild and Heartbeat local runService = game:GetService("RunService") local function preloadUnions() model.Parent = workspace workspace:WaitForChild(model.Name) runservice.Heartbeat:wait() model.Parent = game.ReplicatedStorage end

It would makes things a lot easier if I could gather up all the AssetIds of the unions in the model, but I don't think that's currently possible.

I would really appreciate some help. I've been working on this problem for hours and it's starting to get on my nerves.

1 answer

Log in to vote
1
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
9 years ago

What I do to get around is use a completely opaque set of the unions (to reduce the stress on the client when rendering them) and place them underneath the terrain.

It's worked for me so far.

1
That's a very good idea. To make sure I understand, you make a copy of all the unions in a model and place them under the map so that when you move in the real model, all the unions are loaded? d3lego 10 — 9y
1
Exactly. ROBLOX will load them for you when they're not fully transparent, even if they're behind walls. adark 5487 — 9y
0
Fantastic! I'll have to copy a lot of unions, but it's certainly a more reliable method than what I was using. d3lego 10 — 9y
0
It's also less laggy because no scripts need be run. \o/ adark 5487 — 9y
Ad

Answer this question