Announcement

Collapse
No announcement yet.

How can I make the construction script fire just once

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • started a topic How can I make the construction script fire just once

    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.
    Last edited by Pinworm; 05-31-2017, 09:07 PM.

  • replied
    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...

    Leave a comment:


  • replied
    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.

    Leave a comment:


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

    Leave a comment:


  • replied
    This problem might be connected to this bug: https://answers.unrealengine.com/que...s-on-drop.html
    Unfortunately it looks like it's backlogged for now.

    Leave a comment:


  • replied
    Originally posted by iamjustagamer75 View Post
    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 >> https://answers.unrealengine.com/que...ion-scrip.html

    And maybe this >>https://www.google.com/search?rlz=1C...k1.4G_d4BoPY7Q
    Originally posted by frostic View Post
    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.

    Leave a comment:


  • replied
    Originally posted by iamjustagamer75 View Post
    on event begin play instead?
    I agree with iamjustagamer75.

    Leave a comment:


  • replied
    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 >> https://answers.unrealengine.com/que...ion-scrip.html

    And maybe this >>https://www.google.com/search?rlz=1C...k1.4G_d4BoPY7Q
    Last edited by iamjustagamer75; 05-31-2017, 10:11 PM.

    Leave a comment:


  • replied
    Originally posted by iamjustagamer75 View Post
    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.

    Leave a comment:


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

    Leave a comment:


  • replied
    Originally posted by iamjustagamer75 View Post
    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.

    Leave a comment:


  • replied
    use a do once node????

    Leave a comment:

Working...
X