Is there any way to preload Unions?
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.
01 | local model = game.ReplicatedStorage.UnionedModel |
03 | local function preloadUnions() |
04 | model.Parent = workspace |
06 | model.Parent = game.ReplicatedStorage |
13 | if game.ContentProvider.RequestQueueSize > 60 then |
14 | print ( "Preloading model" ) |
20 | 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.
03 | local function preloadUnions() |
04 | model.Parent = workspace |
06 | workspace:WaitForChild(model.Name) |
07 | model.Parent = game.ReplicatedStorage |
12 | local runService = game:GetService( "RunService" ) |
14 | local function preloadUnions() |
15 | model.Parent = workspace |
16 | workspace:WaitForChild(model.Name) |
17 | runservice.Heartbeat:wait() |
18 | model.Parent = game.ReplicatedStorage |
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.