Blueprint constructor is being executed twice?

I noticed that the blueprint construction scripts are executed twice or more while they are intended to be executed only once.

Since i can’t see any reason for this in my code i’d like to report this as an issue.

Any way to avoid my c++ code to be executed more than once / actor instance?

My blueprint classes inherit from the c++ classes and so the result is unexpected and i have no clue how to deal with it.

Hello ,

I have a few questions for you that will help narrow down what issue it is that you are experiencing.

Quick questions:

  1. What version of the engine are you using?
  2. Where exactly are you seeing the construction script running?
  3. Are you seeing it run multiple times in your game or in the editor?
  4. Could you provide screen shots of what you are seeing?
  5. Can you reproduce this issue in a clean project?
  6. If so, could you provide a detailed set of steps to reproduce this on our end?

Hello Rudy,

Thanks for your time.

1. I am using Engine Version: 4.7.5

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.

So i made a video that shows the problem:

Usually you allocate the memory in your constructors, so its a huge overkill in some cases.

And here is what to do so you can reproduce this issue:

  • Start a new blank project.
  • Create a an actor component c++ code (Any kind of component should do.)
  • Name it UMyTestComponent
  • Add Code:

MyTestComponent.h

UFUNCTION(BlueprintCallable, Category = "Test")
void TestThing();

MyTestComponent.cpp:

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.

Hello ,

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.

Make it a great day

But the construction script ran 3 times when i pressed the compile button. Any explanation to that please?

Hello ,

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.

Make it a great day