Looping through array on construction script - strange results like it refires many times

EDIT: A solution is posted below, however it might not indicate the exact cause, so if anybody knows something more please share, although problem is effectively solved

On construction script of an actor, I have a loop that creates combination of letters for the number of some other actors in the world (there happens to be 174 in this example)

I have a counter that breaks the loop when it reaches this number. That all happens as expected, but afterwards the whole thing fires again… and the results are that are strange:

Function that runs on construction script, part 1:


Part 2: Incrementing through the alphabet. When the counter exceeds the same number as actors array, break the first loop and note that we fire a “Completed” print log.

Full:

Output:


Goes like this all the way to 174…

Then what is happening here???

It goes on like this many times… why is the entire function firing multiple times, and why are the concurrent times that it fires producing nonsense?

A couple other details:

  • There is only ONE actor in the level which fires this function.
  • To make the construction script fire for this test, I am just pressing Compile once.
  • It is a single level, no streaming or composition.
1 Like

Ah, one thing I should have tested before I posted:

I ran it on Begin Play rather than construction script, and then it works as expected. So I think we can chalk this up are just something fishy about construction script? I’ll leave without a solution for awhile just in case anybody knows something, but otherwise it is effectively solved.

2 Likes

Yes, I was just about to say that :slight_smile: The Construction script runs for other reasons too - like when it’s open in a Blueprint Editor…

3 Likes

Construction script fires every time the Actor is updated in the editor I believe. If you move it around in the level, it will fire continuously.

EDIT: But only in the Editor itself. I think if you were to build the game and run it separately then it would only fire once upon first creation.

3 Likes

thanks guys, that explains this weird behavior! I knew about it running when you drag an actor, but I guess i figured if you just clicked Compile once that should only run it once, but i guess that’s not the case.

Well, one more little quirk to remember lol

3 Likes