How can I make the construction script fire just once

I’m trying to make a spline that generates based on a track that you make by placing tiles, and to get around various problems, my solution is for each tile to have a Next Tile and Previous Tile variable.

However, I’m finding this impossible in the construction script, because the actor that you drag into the viewport isn’t the same as when you let go of the mouse…

As in.

I have a bool “bIsPlaced”. It’s set to false. In the construction script, if the bool is false, it sets it to true and prints string.

if I drag in this actor it prints hello twice every time… when you drag it in, and when you let go of the mouse.

You can’t even AddUnique to an array… it adds double the actors, half of them are useless and deleted!

The result is it’s impossible (or I haven’t found the solution) to set the Last Tile variable. Because it’s always overwritten by a deleted actor.

I just want it to fire once so I can set the last tile. Surely there’s a way?

Edit: My solution was to add a flip flop that does nothing on A (the ‘fake’ actor-to-be-dragged-and-placed) and executes on B (when the actor is actually placed.) I guess that’ll do… but it feels like the order could get messed up easily.

use a do once node???

Exact same thing, it executes once when you first drag the actor into the viewport, then again when you let go of the mouse. Do Once will execute twice.

is this actor by any chance replicated or in a multiplayer environment?

Nope all single player. Basic default actors, all I added was a cube and two arrows to server as the spline points.

very weird…i assume you added a print string to verifiy it is infact firing 2x times? If so can this not be done on event begin play instead? Sorry all i can think of to try

Id have a look at this as well >>

And maybe this >>ue4 construction script fires twice - Google Search

I agree with iamjustagamer75.

Begin Play runs when you test the game in the editor. Construction Script runs while editing, which I think is what he wants. That way, the spline updates while being changed.

This problem might be connected to this bug: Construction Script runs 3 times on drop - Blueprint - Unreal Engine Forums
Unfortunately it looks like it’s backlogged for now.

Another idea would be to use a Blutility that runs all your code in the construction script. Maybe that will work?

In case anyone else finds this, there’s a workaround that’s kind of stupid but it does work reliably. Basically you take advantage of the fact that arrays on the actor persist between construction script runs. Just create any array of any type, (bool is easy) add an element to it to act as a gate then the next run check for the length of the array, or for the contents of the element, and branch on that. Either works.

It may work, but its extra overhead.

I have a similar problem with adding mesh components dynamically.

The way to stop the script from building over and over is to create and expose a boolean,
branch the construction script, run the code if the boolean was true, and set the boolean back to false once it’s done.

This also causes issues when building the level in my case - because of the way adding component works though, so you may be able to just block the construction script from firing over and over this way.

also, my array of sorted components doesnt persist between builds at all. Its reset to default empty value as soon as the construction script runs… would have been easy to just keep it…