C
C#3y ago
The Mist

ReferenceEquals?

Am I missing something obvious?
ReferenceEquals(text.textInfo.meshInfo[0].mesh, text.mesh) // true
ReferenceEquals(text.textInfo.meshInfo[0].mesh.vertices, text.mesh.vertices) // false
ReferenceEquals(text.textInfo.meshInfo[0].mesh, text.mesh) // true
ReferenceEquals(text.textInfo.meshInfo[0].mesh.vertices, text.mesh.vertices) // false
This is Unity, TMPro. If text.textInfo.meshInfo[0].mesh and text.mesh are pointing to the same instance - how come the vertices property of the same instance doesn't return true?
25 Replies
Cisien
Cisien3y ago
Are those classes or structs
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Cisien
Cisien3y ago
If they are structs, your dealing with value types, which get copied
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Cisien
Cisien3y ago
Vectors are structs
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
The Mist
The MistOP3y ago
It's an array of value types though Aren't arrays reference types?
Cisien
Cisien3y ago
Vertices is?
Chiyoko_S
Chiyoko_S3y ago
If text.textInfo.meshInfo[0].mesh and text.mesh are pointing to the same instance
if mesh is a value type, those are not "pointing" to the same instance mesh is the value itself so reference equality for a value doesn't make sense
Cisien
Cisien3y ago
Mesh returns true
Chiyoko_S
Chiyoko_S3y ago
right vertices :p but still
The Mist
The MistOP3y ago
Unless I'm misinterpreting the result, looks like an array of structs, yeah
Chiyoko_S
Chiyoko_S3y ago
hm possible that vertices is a property that happens to be returning a new instance of array everytime it's called?
Cisien
Cisien3y ago
Your sure you are pointing at the same array? This wouldn’t be the first time ive seen unity do strange things
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
The Mist
The MistOP3y ago
Ah, yeah, it's a getter that returns a copy apparently, had to view the actual implementation to see that Idk why the IDE didn't show the doctsring, and why it's nowhere in the docs (nowhere I could find anyway)
Chiyoko_S
Chiyoko_S3y ago
yeahhhhh unity is funky
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Cisien
Cisien3y ago
UnityDoesWeirdShit++
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
The Mist
The MistOP3y ago
Yeah, the TMPro documentation is honestly kinda useless I'm still in the process of trying to figure out what the difference between text.textInfo.meshInfo[0].mesh.vertices, text.mesh.vertices and text.textInfo.meshInfo[0].vertices is
The Mist
The MistOP3y ago
The documentation for all of them is just this which is very helpful lol
The Mist
The MistOP3y ago
One youtube video said this:
The Mist
The MistOP3y ago
And I'm not really sure if that's true, if accessing the property always returns a copy - what's the point Maybe one of these doesn't return a copy in some cases Not according to the docstring though text.textInfo.meshInfo[0].vertices this one is an actual array within the meshInfo struct I'll place a few breakpoints to hopefully figure out what it's doing under the hood In any case That's another can of worms So what's the procedure here once a post has been solved, do I close it or do I leave it as it is?
Cisien
Cisien3y ago
you can /close or just leave it
Want results from more Discord servers?
Add your server