Method called only when AACtor is instanciated

I want to build an internal unique permanent ID. To do so, I need to put some code when the actor is instanciated in the editor. Any idea where I could put the code?

Does not seems to be in AActor::OnConstruction, PostActorCreated, PostInitializeComponents, PostSpawnIntialize

OnConstruction and PostActorCreated are both called when you instantiate an actor in the editor. Why do they not “seem to be”?

Isn’t there already a unique ID assigned, using the GUID I think.

2 Likes

OnConstruction called at the first instanciation but also when one parameter is changed (including during the drag and drop of the blueprint). PostActorCreated is also called during drag and drop.

Some guys from EPIC advice me that even if GUID seems unique and permanent for the moment that “may” change.

Well I know that I could handle this by a little trick in the code with an “uninitialized” value to handle the run my code only one time. But I’m trying to be as clean as possible.

I think you’re going to need to make the code idempotent anyway for deserialization, so I think creating an uninitialized state is the right approach. Not sure what type you intend to use for your identifier, but you can reserve one value of it to mean “not yet assigned”. Alternatively you could have a bool flag bIdAssigned and test/set that.