Construction Script (BP) and OnConstruction (C++) Behave differently

Hello.
I was always beliving that both Construction Script and OnConstruction are 2 exactly the same thing, just one is for BP and one is for C++. Either I am wrong or there is a bug in the engine.

Basically, afaik Construction Script destroys all components and recreates them, so if you add any components in it, they will be removed when CS is run again. This would explain why when I procedurally create them, they don’t stay in the world forever.

However when I moved my BP logic into C++ OnConstruction() they started staying so I create hundreds of unwanted components + when trying to manually destroy them from OnConstruction, the engine crashes.

Can someone tell me what is happening and what am I doing wrong?

You need to tell the engine that the components you are creating are components created while the object is constructed. As a result, the engine will destroy them automatically every time.
Here is what you need to set for each component you create within OnConstruction().

NewlyCreatedComponent->CreationMethod = EComponentCreationMethod::UserConstructionScript;

Hope this helps. If you have any other question, please let me know.

Hey, thanks for the answer, I actually managed to get this myself by looking into the source of the engine, altough it took me some time :slight_smile: