Can anyone please tell me why do I have 3x executions at step 4 (instead of none) and then 6x executions at step 6 (instead of 1x)? Depending on the project, I even had between 7x and 10x such “ghost” executions for very similar scenarios.
And yes, I do know that the Construction Script gets executed whenever you drag the actor in the Editor etc., which I did not do, as you can clearly see from the steps above. Feel free to try it out for yourselves!
I simply cannot understand why is this happening, since it’s the root-cause for a much bigger problem I’m having. And please, don’t tell me to avoid using the Construction Script, I really wish to know why it’s behaving this way, as it’s either a bug or a feature that I wish to get to understand. Thank you!
I get some weird function calls every time I start to play in editor, some get called like 3-5x. I have the feeling it is happening after start too, but would always think it is due to my programming
For me I’ve only noticed it with the CS (for a very long time), however, please feel free to give some reproducible examples, if you feel that the issue might be broader. Who knows, you might be on to something, and this behavior is broken on multiple levels…
I think the ConstructionScript gets executed for every frame for every instance while compiling. If you select ClassSettings, please disable RunConstructionScriptOnDrag and see what happens when you drag the instance of the blueprint inside the level and then let go. Does it only show once?
What problem are you facing when the ConstructionScript gets executed 3 times for each instance in a row?
What about functions you can call inside the editor instead of using the construction script?
Hello,@L1z4rD89 and thanks! Well, I can’t actually disable RunConstructionScriptOnDrag because I am using a Blueprint actor, not a C++ one, as it can be seen from my screenshots. But this is not that relevant for me, since I have already stated that I am not dragging my actor through the level, I am very much aware that dragging would trigger the CS to be re-run. If you read the steps I’ve outlined in my first post, you’ll see how my scenario is way simpler than that.
The problem I’m having with this odd behavior is that I rely on the CS to give me some critical information inside the editor (not at runtime). And this throws it off, because not only does it get called more times than needed, but it actually returns very different values (few “correct” ones and a lot of “bogus” ones). For example out of 7x (completely unnecessary) calls that get triggered, 2x - 3x of them give me the correct value, while the other 4x - 5x give me some random stuff.
The behaviour you mention happens in every UE version and is the normal behaviour(as far as I know). When you compile your blueprint the ConstructionScript runs for every instance for X frames while compiling. It is reproducable with your setup from 4.27-5.6.
What do you want to do? Maybe there is another solution for you to become rid of that problem (using another technique)? EditorUtilities? Functions with CallInEditor selected?
Thanks, @L1z4rD89, I forgot about that Class Setting! But as I said, I knew about the dragging thing and it’s not what I’m experiencing. My problem is that the CS runs multiple times when hitting the Compile button. AND I see a very interesting thing you have posted in that 2nd screenshot: Apparently, someone made a bug ticket for this exact issue, and it was marked by the UE staff as “By Design”. Can you please share the actual link to that ticket? Thank you so so much!!!
This will show you every entry about ConstructionScript.
Some numbers to look at:
UE-49006
UE-14743
UE-14061
If you need help to redesign your current blueprint logic you can just post what you want to do and I (or someone else) will show you different ways to achieve your goal
It seems that the general consensus (accepter answer) is that this is “working as expected”, since the reason why we get multiple executions inside the Editor is that the CS is being ran for each frame while the BP is still compiling.
However, I have now managed to find an entirely different explanation under this Reddit post:
If you read the replies between BARDLER and AshenBluesz, you’ll see that apparently the CS runs 3x times (same number observed by me, as well as all other users in the above UE links) because:
One run happens on “spawn actor”
One run happens on “post load”
One run happens on “post change properties”
So now I am a bit confused: Are we getting those 3x CS executions because of the 3x frames it takes the Blueprint to compile (and the CS being ran for each frame while compiling), OR because of these completely different 3x triggers outlined by the Reddit post above?
Please let me know what you think and how these different sources of information conflict with (or confirm) one another? Thank you so much!!!
Yeah, I’m just not sure why this isn’t better documented on their official UE docs page for the CS. Cause it’s clear that:
People expect a different type of behavior
The current behavior is extremely non-intuitive
Nobody knows exactly “why” it acts that way or how it actually works, it’s just some speculation here and there about “what UE does under the hood”, but I’m still treating it as rumors, having some possibility of truth somewhere in those explanations