createFromObjects() doesn't copy the object id nor the gid

I’m using Tiled to create maps and i have a bunch of objects, I’m using map.createFromObjects() to generate objects and, properties such as position, size, rotation are being copied, but not the ID nor the GID

Here is an object in Tiled with its properties
image image
As you can see it has ID, Name, Type, X, Y, etc… the GID is not shown by Tiled but it’s in the json


Here’s how i generate the map
image
And when i do a console log
image
I can clearly see all objects with all the correct data (id, name, type, rotation, etc)

And then i use createFromObjects with a custom class


In my class i have a created() function with a console.log to see all the properties
image
The result is as expected, it creates a Sprite with all the properties except ID or GID. I can’t find it

The documentation says that it should copy all properties, but i checked inside data and everywhere but i can’t find ID nor GID.

Does some one know if this is intended or do they plan in adding this feature?

:wave:

I think that’s intended. It means all custom properties are copied onto the Game Object (if a matching property exists) or onto its data store (otherwise).

But I need the ID.

In Tiled you can connect objects, and to do this it uses the ID


In my example I have a button that when it gets pressed it should trigger a platform to move, I have the ID of the platform because it copies the custom property, but now I need to find that platform to apply some movement, but I cant do this because my Platform class doesn’t receive it’s corresponding ID

I think you’ll need to copy and modify Tilemap#createFromObjects().

Well, thanks for the answers, what i will do is define a custom property and let createFromObjects() handle it, because now i realize that i might need to reference various objects and i cant do that having only one id

The createFromObjects() function is really nice for some things, but if you want access to the information you put in your question I would try the getObjectLayer() function. It essentially mirrors the JSON for that object layer and you can iterate through the objects in the resulting data structure to get information that isn’t coming along with your createFromObjects().

1 Like