2. I have made a Custom Component in C++.
I added this component to a Simple Blueprint Actor class.
But i noticed this issue before already, and i just ignored it but it causes a head ache this time.
The load level function is part of the Custom Component.
I am using UE_LOG() method to debug what my code is doing
3. I see it running multiple times in the editor. When i am compiling the blueprints and when placing the actor into the level. I made a couple of hot-reloads, but when i restart the project i get the same output twice or more times printed in the output log.
5. It is a clean project, i started a few days ago
6. Yes sure, checkout my second comment for detailed set of steps.
int g_Runtimes = 0;
void UMyTestComponent::TestThing()
{
UE_LOG(LogTemp, Log, TEXT("It is running %d times."), g_Runtimes);
++g_Runtimes;
}
Compile
Start the project
Create a new Blueprint Class
Add our new component
Make the construction script to look like this:
Output Log after pressing Compile:
LogTemp: It is running 0 times.
LogTemp: It is running 1 times.
LogTemp: It is running 2 times.
Output log after putting the action into the level:
LogTemp: It is running 3 times.
LogTemp: It is running 4 times.
LogTemp: It is running 5 times.
LogTemp: It is running 6 times.
LogTemp: It is running 7 times.
LogTemp: It is running 8 times.
LogTemp: It is running 9 times.
So the constructor executed 10 times, and all i did is i pressed compile and put the actor into the level.
After looking over the information provided and running through your code. I believe that the engine is working as intended. The reason that your construction script ran 9 times was because the construction script updates every frame while changes are being applied to the actor in the scene. This will not be the case during game play. Once the actor is created it will not run the construction script again unless the actor is destroyed and then added back to the scene. I hope this information helps.
After looking into the issue further I have decided to write up a report (UE-14061) for this part of the issue. I have submitted it to the developers for further consideration. I will provide updates with any pertinent information as it becomes available. Thank you for your time and information.