Detect if Model has Finished Streaming In

Enabled Streaming makes a huge impact reducing performance overhead and is incredibly useful to use; however, it is not without its drawbacks and limitations.

In War Tycoon we have Street Lights that need to be able to turn on/off dependent on various factors. Factors such as the time of day, as well as if it has been knocked over by a player. We are currently handling this logic using the CollectionService, which most of the time works like a charm.

When a Street Light model streams in, it gets added to the CollectionService. When a Street Light model streams out, it gets removed from the CollectionService. In the logic we need to check for specific instances in the model. The “LightPart” to change the material between Enum.Material.Glass and Enum.Material.Neon. The Beam to enable / disable. As well as the SurfaceLight itself to enable / disable.

We cannot use FindFirstChild because these instances do not always stream in immediately with the rest of the model. We CAN use WaitForChild; however, it would be more efficient for a developer to have a way to detect when a model has finished fully streaming in, rather than using multiple WaitForChild methods to determine.

It is also worth noting that having multiple WaitForChild method calls could have edge-cases where a model starts to Stream In, the code gets through one WaitForChild, the model Streams out, the code attempts to call for another WaitForChild, and then the code errors because the instance we are calling WaitForChild on, no longer exists.

It would be really helpful to have a method of detecting if a model has streamed in. Either through a Method call on the Model, an Event that triggers when it has fully streamed in or out, or even a boolean property on the Model. That way we only need one check for when everything has Streamed In.

Or you could just set the StreamingBehavior to Atomic?

3 Likes

As @SoCalifornian suggested, we recommend setting the model to be atomic in situations like this. Without atomicity any signal would have the risk of firing right before some descendant instance in the model is streamed out.

Another option is to use improved model streaming:

This will have behavior similar to atomicity in many situations, but keep in mind improved model streaming impacts the behavior of all models in workspace.

3 Likes