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

**URL:** <https://phaser.discourse.group/t/createfromobjects-doesnt-copy-the-object-id-nor-the-gid/11011>\
**Category:** Phaser 3\
**Created:** [January 8, 2022, 8:38pm UTC](https://phaser.discourse.group/t/createfromobjects-doesnt-copy-the-object-id-nor-the-gid/11011 "2022-01-08T20:38:53Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![LautaroRobles](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/lautarorobles/32/6087_2.png) [@LautaroRobles](https://phaser.discourse.group/u/LautaroRobles)\
**Post date:** [January 8, 2022, 8:38pm UTC](https://phaser.discourse.group/t/createfromobjects-doesnt-copy-the-object-id-nor-the-gid/11011/1 "2022-01-08T20:38:54Z")

</div>

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](https://global.discourse-cdn.com/free1/uploads/phaser1/original/2X/2/2305086fac096726c9ba1732f02ab3e3cb1c684d.png) ![image](https://global.discourse-cdn.com/free1/uploads/phaser1/original/2X/f/f84906b13f97f0ecf4f9506871b5b98c7f59a1ff.png)  
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](https://global.discourse-cdn.com/free1/uploads/phaser1/original/2X/6/67e8071dc3b7779faa13e4dee6d3d2222d8489d5.png)  
And when i do a console log  
 ![image](https://global.discourse-cdn.com/free1/uploads/phaser1/original/2X/8/84700f970945db50ea099c28b1631a87e6a75cf7.png)  
I can clearly see all objects with all the correct data (id, name, type, rotation, etc)

 ![image](https://global.discourse-cdn.com/free1/uploads/phaser1/original/2X/8/8c11c7394cf42698eb39097cbaabd89d22b373b7.png)

And then i use createFromObjects with a custom class

 ![image](https://global.discourse-cdn.com/free1/uploads/phaser1/original/2X/9/9f30723b5be3aabe3aecae6a5ad02cc8d87f86ab.png)  
In my class i have a created() function with a console.log to see all the properties  
 ![image](https://global.discourse-cdn.com/free1/uploads/phaser1/original/2X/4/48ac4758d3f39343454a2666c02037226b24e226.png)  
The result is as expected, it creates a Sprite with all the properties except ID or GID. I can’t find it  
 ![image](https://global.discourse-cdn.com/free1/uploads/phaser1/original/2X/1/145becbf8d250d36c0bde72c38fc7f7f21bc2979.png)

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

 ![image](https://global.discourse-cdn.com/free1/uploads/phaser1/original/2X/e/ef51ff14e46db39015f468fea071e7e1a3c5d56a.png)

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

---

<div class="post-metadata">

**Author:** ![samme](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/samme/32/5275_2.png) [@samme](https://phaser.discourse.group/u/samme)\
**Post date:** [January 8, 2022, 8:51pm UTC](https://phaser.discourse.group/t/createfromobjects-doesnt-copy-the-object-id-nor-the-gid/11011/2 "2022-01-08T20:51:07Z")

</div>

👋

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).

---

<div class="post-metadata">

**Author:** ![LautaroRobles](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/lautarorobles/32/6087_2.png) [@LautaroRobles](https://phaser.discourse.group/u/LautaroRobles)\
**Post date:** [January 8, 2022, 9:09pm UTC](https://phaser.discourse.group/t/createfromobjects-doesnt-copy-the-object-id-nor-the-gid/11011/3 "2022-01-08T21:09:41Z")

</div>

But I need the ID.

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

 ![image](https://global.discourse-cdn.com/free1/uploads/phaser1/original/2X/b/b05095e72be0744dc5a5b88efd3b7efc4eb86d62.png)  
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

---

<div class="post-metadata">

**Author:** ![samme](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/samme/32/5275_2.png) [@samme](https://phaser.discourse.group/u/samme)\
**Post date:** [January 8, 2022, 9:20pm UTC](https://phaser.discourse.group/t/createfromobjects-doesnt-copy-the-object-id-nor-the-gid/11011/4 "2022-01-08T21:20:36Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![LautaroRobles](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/lautarorobles/32/6087_2.png) [@LautaroRobles](https://phaser.discourse.group/u/LautaroRobles)\
**Post date:** [January 8, 2022, 10:00pm UTC](https://phaser.discourse.group/t/createfromobjects-doesnt-copy-the-object-id-nor-the-gid/11011/5 "2022-01-08T22:00:21Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![chemdatafarmer](https://avatars.discourse-cdn.com/v4/letter/c/e19adc/32.png) [@chemdatafarmer](https://phaser.discourse.group/u/chemdatafarmer)\
**Post date:** [January 9, 2022, 12:54am UTC](https://phaser.discourse.group/t/createfromobjects-doesnt-copy-the-object-id-nor-the-gid/11011/6 "2022-01-09T00:54:55Z")

</div>

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().
