TehSomeLuigi Posted May 29, 2014 Share Posted May 29, 2014 I'd like to be able to refer to another entity/prefab from my another (my own) entity/prefab and keep this reference intact when saving/loading the game. The first thing that came to mind would be using the ID of the entity - however, I can't find such a thing. The closest I've found is entity.GUID - but that does not persist, so I can't use that. Is there a proper way to do this? If there isn't, I think I can do some magic to assign my own unique ID numbers to the entities/prefabs I'm interested in, but I wanted to see how the proper way is to do it, if there is one. Also, is there some documentation to the fields and functions that the userdata types have? e.g. entity.AnimState and so on? Cheers in advance. Link to comment https://forums.kleientertainment.com/forums/topic/36961-getting-a-persistent-reference-to-another-entityprefab/ Share on other sites More sharing options...
debugman18 Posted May 29, 2014 Share Posted May 29, 2014 I'd like to be able to refer to another entity/prefab from my another (my own) entity/prefab and keep this reference intact when saving/loading the game. The first thing that came to mind would be using the ID of the entity - however, I can't find such a thing. The closest I've found is entity.GUID - but that does not persist, so I can't use that. Is there a proper way to do this? If there isn't, I think I can do some magic to assign my own unique ID numbers to the entities/prefabs I'm interested in, but I wanted to see how the proper way is to do it, if there is one. Also, is there some documentation to the fields and functions that the userdata types have? e.g. entity.AnimState and so on? Cheers in advance. You could use onsave/onload and assign an inst.tie (or inst.whatever) value using math.random to generate it and work from there. Link to comment https://forums.kleientertainment.com/forums/topic/36961-getting-a-persistent-reference-to-another-entityprefab/#findComment-490788 Share on other sites More sharing options...
simplex Posted May 29, 2014 Share Posted May 29, 2014 The GUID persists if another saved entity keeps a reference to it. Check the OnSave method of the leader component (doing it from the prefab's OnSave is also possible, but a bit different). Link to comment https://forums.kleientertainment.com/forums/topic/36961-getting-a-persistent-reference-to-another-entityprefab/#findComment-490791 Share on other sites More sharing options...
TehSomeLuigi Posted May 29, 2014 Author Share Posted May 29, 2014 (edited) The GUID persists if another saved entity keeps a reference to it. Check the OnSave method of the leader component (doing it from the prefab's OnSave is also possible, but a bit different). Thanks a lot! This does indeed work! For anyone else stumbling upon this, I'll make a quick note:In a component :OnSave, the second return value that you should provide is a table of the GUIDs of the entities you are interested in.In the component :LoadPostPass(newents, savedata), the first parameter is a table which has a mapping of all the entities (I think - but this isn't relevant), but more importantly, using the old entity's GUID as a key (e.g. newents[oldGUID]) gives you another table. In this other table, the entity field gives you the new instance of the entity. (e.g. newents[oldGUID].entity) The same can be done with a prefab/entity's .OnSave, except that the table is the first (and only) return value.Then you can define .OnLoadPostPass which has the same parameters as the component version. If that doesn't make sense to you, go and take a look at the leader component (as simplex mentioned), the Leader:OnSave and Leader:LoadPostPass methods. Edited May 29, 2014 by TehSomeLuigi Link to comment https://forums.kleientertainment.com/forums/topic/36961-getting-a-persistent-reference-to-another-entityprefab/#findComment-490855 Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now