Absolute minimal way of implementing a "run only on initial scene load"?

BacktothisBacktothis Member, PRO Posts: 75
So basically let's say there's a little bit of initialization I want to run at the start of each scene, maybe a camera thing or position offsets or something. The way I've thought about doing it now is to have a variable, call it "initialLoad", which is set to true to begin with.

We also have an actor, call it "initialize", which does the initialization. At the end of initialize, initialLoad is set to false, and initialize only does its work if initialLoad is true.

Then immediately before any scene transition, we set initialLoad to true (theoretically the scene transition should be the next executed command right? So no race conditions that could cause weird things to happen should ever happen).

Is there any better way of doing it? My main concerns right now is that it just feels unelegant having the implied (rather than explicit) necessity of having a specific change attribute in front of every scene transition. I'm also not quite sure if I'm correct in assuming there is no race condition.

Comments

  • natzuurnatzuur Member Posts: 304
    edited March 2014
    If you just leave a behaviour with zero rules on an actor in each scene it will trigger just once, and that's at the begining of the scene load. No boolean rulesets needed.

  • BacktothisBacktothis Member, PRO Posts: 75
    I wish I could show you how low my jaw is hanging right now. That is just amazing, thanks xD

    So basically inside an actior, its like

    Rule 1 {}
    Rule 2 {}
    Rule N {}
    Behavior 1 {}

    And behavior 1 only triggers once? I never knew that lol.
  • natzuurnatzuur Member Posts: 304
    edited March 2014
    Yes, I would personally trigger behavior 1 first as actors rules/behaviours trigger from top to bottom (layers trigger from bottom to top). So an actor on the bottom most layer with behaviour 1 at the top would trigger first thing once the scene loads. But that's the gist of it.
  • BacktothisBacktothis Member, PRO Posts: 75
    But if the behavior needs to be triggered by a rule, say by the value of an attribute that is set based on the resolution of the device (so basically if its iphone 5 or 4, in order to change the camera view appropriately), then the booleans are needed right?
  • natzuurnatzuur Member Posts: 304
    But if the behavior needs to be triggered by a rule, say by the value of an attribute that is set based on the resolution of the device (so basically if its iphone 5 or 4, in order to change the camera view appropriately), then the booleans are needed right?
    Correct.

  • BacktothisBacktothis Member, PRO Posts: 75
    Ah, well darn I wish there was a bit of a prettier way to do that.
Sign In or Register to comment.