ldtk icon indicating copy to clipboard operation
ldtk copied to clipboard

Inquiry About the Integer Limit for Custom Entity Fields in LDtk

Open mungsaja opened this issue 1 year ago • 3 comments

Hello,

I’ve been working with LDtk and noticed that when setting custom fields for entities, the maximum allowable integer value seems to be capped at 2,000,000. Could you please clarify the specific reason for this limit? Is it due to JSON handling, internal engine constraints, or another technical consideration?

thanks.

mungsaja avatar Aug 30 '24 17:08 mungsaja

I honestly don't think there's a real reason other than me quickly figuring out a cross-platform limit to Integers when I entered that value.

If you happen to have a better idea on that limit on most classic platforms (JS, C#, C++, etc) that would be super useful and I could adjust the limit accordingly 👍

deepnight avatar Sep 07 '24 09:09 deepnight

I honestly don't think there's a real reason other than me quickly figuring out a cross-platform limit to Integers when I entered that value.

If you happen to have a better idea on that limit on most classic platforms (JS, C#, C++, etc) that would be super useful and I could adjust the limit accordingly 👍

First of all, thank you for your reply. I couldn't find specific guidance on the integer limit, so I assumed that the maximum value of a 32-bit integer, which is around 2.1 billion, would be possible. Based on this, I assigned custom ID values exceeding 2 million to entities across various levels. Since the values appeared as entered until the saving process, I didn’t realize the issue until after importing the data into Unity. Upon import, I saw that the values for all entities were reset, which made me realize there was a limit.

It would be great if the full range of 32-bit integer values could be used. Alternatively, it would be helpful to have visual feedback in the input field when the limit is exceeded.

mungsaja avatar Sep 08 '24 02:09 mungsaja

The limiting factor is likely JavaScript, where the native number type can only accurately represent integers from Number.MIN_SAFE_INTEGER to Number.MAX_SAFE_INTEGER. Alternatively, JS has BigInt which I've never used, but I think that would require changing a bunch of code to parse strings and JSON into BigInt everywhere you're handling custom fields.

Number.MAX_SAFE_INTEGER is 2^53-1. Number.MIN_SAFE_INTEGER is -(2^53-1).

This far exceeds the range of 32bit integers, but doesn't reach the range of 64bit integers.

cspotcode avatar Mar 18 '25 01:03 cspotcode