I’ve been trying for a while to create a unique identifier for Actor Component and for now I can’t seem to suceed !
What I want to do is having a component attach to an actor via blueprint or cpp generate a unique ID when dropped in world in editor.
I’ve tried lots of ways but for now I can’t seem to be able to generate a stable unique ID for a component without implementing it in the actor construct below.
I’ve tried a lot of different overiddes taking account of the CDO … but for now it seems impossible
So maybe to be a bit more clear: 1 Actor with 1 component attached to it.
Let’s drop it 200 times in world (the same actor), each of the 200 components on each actor should be uniquely identified.
If the world was to reload or the PIE restart they should keep their ID.
(And no just putting in construct if(Guid.isValid()){ Guid = FGuid::NewGuid()) } won’t work)
I wouldn’t have a Generate ID button – just generate it, post-demarshal, if the field is empty. As in, override the demarshal (or maybe even begin play) hook, to do it there.
Is it possible to invalidate the guid on a duplicate?
I think there’s a post-duplicate callback, but that may not capture all cases (like copy/paste, or import subscene.) You might keep a list of all IDs that have been used, and if you find the ID you load is already in that list, detect it as a duplicate. (You have to remove the ID when the component is disposed, too.)