GetPolySpatialIdentifier returns wrong identifier

Hello,
I’m using GetPolySpatialIdentifier to extract PolySpatial ID of a gameobject, then transfer it to Swift and display some SwiftUI attachment over this object. It works perfectly for objects that were initially in the scene. For any object created in runtime, this code

                    let packedIdentifier = PackedIdentifier(id0: attachment.polyspatialID, id1: 0)
                    if let entity = PolySpatialWindowManagerAccess.entityForIdentifier(id: packedIdentifier) {

fails to find an entity. I noticed that objects that work fine receive ids like 7290, 7320, etc. In general - small numbers. But from the other hand, if object was generated in runtime, it received 4294966792, 4294966774, etc.

Do you know what could be the reason?

Thanks,
Michał

Forgot to mention - I’m using 1.2.3

Yes; objects that are generated at run time in Unity receive negative instance IDs, and the numbers that you’re seeing are the result of interpreting a negative 32-bit integer as an unsigned 32-bit integer (4294966792 → -504). You should be able to use Int32(bitPattern:) to convert the unsigned value to a signed one.

Thank you! It worked.
Since we are getting uint64 from entityForIdentifier and PackedIdentifier requires uint64 too, following trick did the work:

    func castAndConvert(_ input: UInt64) -> UInt64 {
        let int32Value = Int32(truncatingIfNeeded: input)
        return UInt64(bitPattern: Int64(int32Value))
    }```
1 Like