DescendantAdded with models

If I add a model to workspace, which of the following happens?

  1. Each child in the model gets added to workspace and then DescendantAdded is fired before adding the rest of the children.
  2. All the children are added to the model and then DescendantAdded is fired for all the children.

I’m essentially asking if I can trust that the whole model will be there before any of my DescendantAdded code runs.

2 happens

1 Like

The 2nd behavior appears to happen in most cases, but there is currently nothing guaranteeing that it happens in all possible cases, or that the cases in which it does happen will continue to be.

In short, both do, and you should be prepared for either.

To elaborate on my answer, this is heavily dependant on what you are inserting, and a lot of variables can cause massive and unpredictable changes in the behaviour of DescendantAdded. Some of the key factors you should be looking at are:

  • Amount of instances
  • Union / Mesh complexity
  • Server lag

I think it’s safe to assume all the members of the model get added in the same update loop iteration and the DescendantAdded listeners get fired in subsequent update loop iterations. The server window tends to freeze up when adding a ton of instances, so that’s probably an indicator that it’s all being added in the same frame instead of being split up into different frames.