Inconsistent object identities with Vector3s vs Vector2s.


vector_indentity_output

Vector2s created with the same coordinates do not refer to the same object. This created a confusing bug in my game, as I was using them to index tables and assumed they behaved like Vector3s.

I’m running Windows 10 on an 11th Gen Intel(R) Core™ i7-11700F @ 2.50GHz

Here’s a blank project with a Script in ServerScriptService that reproduces the problem.
inconsistent_vector_indentity.rbxl (57.0 KB)

Expected behavior

I would expect value “A” to have been overwritten with value “B”, since it was written to the table after “A” and seemingly had the same key.

I would also expect Vector2s to appear as their contents when used as keys like the Vector3 does in the image.

Hello.
This is correct, each Vector2 object is userdata type where each one has a separate identity.
Only Vector3 is special being a value type.

You can read our initial announcement to learn more: Native Luau Vector3 Beta
The important part referring to your report is here:

We do not have plans to change any behaviors here.

1 Like

Alright, understandable, although I do wish this was in the documentation instead of buried in a forum post.

We will add this information to the documentation.

2 Likes

Hi @MikeMan0142 ,
I’ve updated the Vector3 docs with a note here. Thanks for flagging this.
https://create.roblox.com/docs/reference/engine/datatypes/Vector3

Best regards,
IgnisRBX

1 Like

I appreciate the change, but it seems to have been removed recently? I remember the page had mentioned something about atomic data types before it got reverted.