Jump to content

Unique entity ID


Ywa
 Share

Recommended Posts

Hi guys,

 

Is there a way to get some sort of unique entity ID (or index in scene)? In the C++ headers I see some possible variables, but none seems to be documented in the Wiki. And I would like to have something in Lua.

 

Thanks in advance.

Link to comment
Share on other sites

What I am doing is using the memory address as recommended by Josh. entity->GetAddress().

 

This isn't a bad idea, however what if the entity was removed; would a new entity not be able to take it's old memory address?

Perhaps it'd be best for Josh to add something like App:OnEntityCreated() so people can manually track Entities, of course this would have to be called for each entity created in the map as well when they are created.

Link to comment
Share on other sites

Give the name of the entities in the map unique names and use that. If they are run-time entities then you would need to save them off yourself anyway since you can't save them in the LE map.

I'll consider 'syncing' by name yes. Although I would still have preferred some sort of ID system.

 

Thanks

Link to comment
Share on other sites

I'll consider 'syncing' by name yes. Although I would still have preferred some sort of ID system.

 

Thanks

 

You could always manually track entities and assign them IDs, make your own function for creating entities that inserts them into a global entity table, and make a callback function when the map is loaded that inserts those entities into the global entity table.

 

Someone linked me a page that had:

if Map:Load(mapname,"Callback") == false then return false end

"Callback" being the name of a function, you could create a function like:

_G.entities = _G.entities or {}
local function Callback(ent)
ent.id = #_G.entities+1
table.insert(_G.entities, ent)
end

 

Note: I'm only refering to the entities table with _G in-case you already have a local 'entities' table in that file.

 

I personally would prefer LE force unique names in a map. I hate that you can have the same names in a given map. Just seems to go against reason to me smile.png

 

Agreed.

  • Upvote 1
Link to comment
Share on other sites

I didn't know I could load a map with a callback. This will work perfect. Thanks CrazyCarpet.

 

And I agree with the unique naming. I would also like to have everything in lower case (filenames and entity names).

Link to comment
Share on other sites

I didn't know I could load a map with a callback. This will work perfect. Thanks CrazyCarpet.

 

And I agree with the unique naming. I would also like to have everything in lower case (filenames and entity names).

 

Not a problem, as for the lowercase filenames, Josh made reference to it being a problem on Unix-based systems as they have a case-sensitive filesystem, it'd be possible for it to cause problems..

Link to comment
Share on other sites

  • 6 years later...
On 03.10.2014 at 17:37, Rick said:

Haritadaki varlıkların adlarına benzersiz adlar verin ve bunu kullanın. Bunlar çalışma zamanı varlıkları ise, onları LE haritasında kaydedemeyeceğiniz için yine de kendiniz kurtarmanız gerekir.

Is there a sample code that I can refer to for lua what you said.

Link to comment
Share on other sites

In the new engine, each entity in a scene has a unique UUID. These can even be used to identify entities in multiplayer games over the network.

  • Like 2

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...