Feedback on "Instance"

This page used to specify that GetChildren() returned children ordered by which objects had been added (parented) to the object first. Now it says the order is unspecified. Which is it? Is code that relies on the behavior that GetChildren() returns children that were parented first in the first indices stable? If not, then the breaking change should be explicitly documented.

Affected URL: https://create.roblox.com/docs/reference/engine/classes/Instance#GetChildren

Hello @asadefa . Thanks for reaching out!

The GetChildren() documentation was updated to reflect actual behavior as the method doesn’t always return in the expected order. This isn’t a change in engine functionality, rather a fix to the documentation to resolve an inaccuracy.

As mentioned in the documentation, the recommendation is to perform manual sorting instead of relying on the returned order.

Note that the array is not sorted in any particular order, so manual sorting (for example using table.sort()) is advised for sorting the children returned by this method.

While no actual behavior was changed, I’ll see where we can surface this documentation fix in other avenues to make more creators aware (this bug report helps!). I appreciate you double checking with us and please reach out if you see any other inconsistencies.

Have a great day,
naahchos

Based on my testing and older documentation I could find, GetChildren() will return a consistent order as long as the objects were placed into the parent in the consistent order. However, when children are replicated to clients, their replication order might be non-deterministic or random, so GetChildren() on the client might return a different order than on the server, even if the server ordering is deterministic. Can you determine if the above is the reason why GetChildren() sorting has been updated to say ā€˜non-deterministic’? If so, then the documentation should be updated to say, ā€˜Yes, the order is consistent on the server or client-created objects, but replication order is non-deterministic.’

Hi @asadefa .

I’ll reach out to the individual who made the documentation change to see if they want to include your suggestion. It’s possible that this specific sorting behavior is not something that Roblox can guarantee will remain static now or in the future, even if your own tests seem to be consistent.

I’ll make sure to update the documentation if I hear anything differently. Thanks!

3 Likes

Hi! That individual, here! We’ve always had the stance that this order can change at any time, but the documentation incorrectly reflected that (as naahchos said).

The reasoning here is that we reserve room to make optimizations in the future, so that order may change, and we don’t want people relying on specifics. Ideally, the table is a set, but since those don’t really exist in Luau, we can’t have the return type reflect that. We don’t want to document any particular order because that would lead developers to think that they can rely on the behavior not changing, not because we don’t know the specifics of what order :GetChildren() returns.

Thanks for the reply, but my concern is that since that was documented at some point, there may be some unknown amount of legacy code that does rely on the previously documented order, despite us now learning that we should not rely on the order. By not having the order documented anymore sort of opens the door to code that was ā€œguaranteedā€ to work at the time the specific ordering was documented but could break at a future time.

I feel that for the purpose of preserving legacy code that, at the time, was ā€œto the letterā€ correct, the order should be preserved and documented. If there is an unordered but more optimized function added in the future, that should probably get a new function. GetChildrenFast(), GetChildrenUnordered(), etc.

Or if you still do not want to do that, I would add a note in the documentation that says something like:

Warning: Currently GetChildren returns children by the order their parent was set to the object, but this behavior could change at any time and should not be relied on.

This would make the documentation change more transparent and document the current behavior without making a long-term guarantee.

To my knowledge, the documentation wasn’t incorrect for too long, and any code that was written with it in mind was never guaranteed to work, even if it followed this documentation to the letter. Like you said, there are situations, like replication, where code could look like it works and then break under different circumstances. We’ve had this stance for as long as :GetChildren() has existed, and it was documented at once point, to my knowledge. I’ll check with the docs team to see when the old sentence specifying the ordering was introduced, but saying anything about the ordering on the docs page feels like it gives information that we explicitly don’t want developers to use.

At this time there are no plans to change the ordering of :GetChildren() for the basic case, and there will certainly be internal talks if we ever do want to change it, as well as case studies and profiling to see what, if anything, breaks. We may determine that we shouldn’t change the order regardless, depending on the cost. We likely wouldn’t introduce multiple :GetChildren() methods- if there’s a reason to change the order for optimization, we want all games on the platform to get that optimization.

I believe the documentation change was made at most a few months ago, and I found some archives going back to 2019 documenting the explicit ordering: Instance:GetChildren

Although I might not be able to find older archives at the moment, the documented ordering might go back far earlier than 2019.

Ok that is pretty old, dang. Here’s a post from 2018 clarifying the correct behavior:

Rest assured though, if there’s ever discussion about changing the behavior the community will be notified to get input.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.