Is there a method to distinguish/separate the code between editor version and built version (in C++)?

I have a static value in my actor and it would change and assign to another non-static value once a actor is spawned.
For some reason, some actors have to be spawned in the editor by the designer and would be saved in the map later while some others would be spawned ‘automatically’ in the built version during runing without saving in the end.
However, the static value is reset once the editor is closed and it is obviously that it would be not kept in built version, either. Thus, is there a method to distinguish/separate the code between editor version and built version, so that I can design a condition logic to avoid conflict.
Thank you!

I am not familiar to this part, it may be something like:


Can you show what you have so far?

Could you elaborate on this? Values don’t reset if they are saved in the class???

It is actually a counter in my actor class which would be assigned to 0 in the beginning, like
static int counter = 0;

You could simply increment on BeginPlay. BeginPlay gets called on both spawned Actors and Actors already in the Level.

The counter is to record the number of spawned actors and its increment is finished on PostActorCreated() since some of the non-static value is initialized at BeginPlay in its components according to the counter value. The main problem is still the static value, which would be reset/losed after built. I don’t want to use a gamesave system, because the actors should not be spawned in editor in the final version. It was just designed for my groupmate to debug.

As my descriptions don’t seem to be detailed enough, I’ve just edited them.

What I found was that the non-static values which are assigned at PostActorCreated() in the editor didn’t change in built version because they had already finished calling PostActorCreated() in editor mode and do not need to call agian in built version.

What I actually need is a function like ‘Pre’ BeginPlay that runs once like BeginPlay but I only found PostActorCreated().