Hello, is there a way to make a check if actor is placed from the editor or spawned from the code?
The best thing to do in this case is to create a boolean variable for all C++ created actors, for example:
bool bNotEditorSpawned
And obviously when spawned in C++ set it to true and everything that’s false is an editor placed actor. As far as I know that is the only way to do it.
I have tried this way and it didn’t work well for me. I’m trying to set actor before spawning it from the code.
The preview actor will have the RF_Transient object flag. You can check with Actor->HasAnyFlags(RF_Transient). Transient means not saved.
I know this is old question but its top search on google. So to answer the question directly, a GetFlags();
on the actor will reveal the most reliable flag being RF_WasLoaded for editor spawned actor. But only IF the actor was spawned in from a saved map. It is possible to have NO RF_WasLoaded flag if; you drag actor into level, and hit play.
However if you drag the actor into level, SAVE, then hit play, the actor will receive RF_WasLoaded flag everytime!
You can then do a simple if(HasAnyFlags(RF_WasLoaded)){ //im an editor actor! }
like so.
Bingo! Works like a charm.
There is AActor::IsNetStartupActor which returns if an actor was placed in a level or spawned at runtime (if the actor has a valid path). I think that might be a good solution for checking this.