Continue, Hold, and Complete

Effect.ContinueIf can be a very important action. This allows you to test for some condition and stop processing if that condition is ever false.

A common thing to test for is “someGameObject == true” because if a gameObject has been disposed then a test of true or false on that gameObject will return false. If there’s even a tiny chance of this happening then you should check for it. If you skip the check for dead objects and one of your objects dies then your app will end up throwing a lot of exceptions in that rare case that it does happen. If you set your objects to null when they should be dead then you can check for null.

Some other ways you might use Effect.ContinueIf is to check to make sure an object is visible and/or enabled before you try to move it. OnDone (which is covered later in this post) will fire if the effect was stopped in the middle of doing it’s thing, and OnComplete will always fire. So you can use those actions to do the final thing (like enable the menu) but skip the transition period when the object is not visible. Some types of objects will actually throw errors if you try to move them when they aren’t visible, and it’s usually a better user experience for the user when they don’t see the tail end of movements that they never saw the beginning of, so checking ContinueIf and using OnDone or OnComplete is a good practice to get into.


Effect.HoldEffectUntil is an action that takes the reference and a float. The float represents the time the effect has been held so far, so that you can time out the hold action if that number gets too large. If you set HoldEffectUntil then the effect will poll this delegate every frame before the effect actually starts running until the action returns true.

HoldEffectUntil has two common uses:

  1. It can be used to set up an effect now, but hold off actually running that effect until some condition is met. For instance in Demo #3 we set up all the effects to return to home, but hold them until the home base receives an OnCollisionEnter event.
  2. The other common use is as a stop and go mechanism. For example, lets say that you have a character who is walking along using the sequence “put right foot forward, put left foot forward, repeat.” You could have logic in your script that set a boolean (lets call it beingLookedAt) to true when the camera can see the player. If you define HoldEffectUntil on those two effects to hold until beingLookedAt was false then the characters would walk only when the player wasn’t watching them (kind of like that cat in that video).

There are two actions which can by surprisingly handy in certain situations: Effect.OnDone and Sequence.OnComplete.

Both of these actions pass in the reference and don’t return any values. As the name suggests, they are executed when the Effect or the Sequence completes. They have several common uses:

  1. There are quite a few instances in which an Effect is really just a prelude to doing some action. For instance, if you are deleting an element on the screen you might want to move that element over to a trash can icon and once it’s done moving then call Destroy. Or, when opening a menu, you might want to slide the menu out and then, once that has finished, enable the buttons on it. In these cases you want to assign one of these two fields to your ending action.
  2. You can use these actions to chain different types of effects together. For example, you may have noticed that the type of variable that an effect manipulates can’t be changed between one effect and another inside a sequence. So if you wanted to move an item 3 units in the x axis and then rotate it 20 degrees you would have to define two separate sequences and then chain them together using OnDone or OnComplete.
  3. You can also use one of these functions if you want one effect to turn into more than one effect. For instance, if you were using an effect to control billiard balls on a pool table and the billiard hit two other pool balls at the same instant you could start a sequence for both of the new balls using OnDone or OnComplete.
  4. You could use OnComplete to repeat the sequence if it should only repeat when some complicated condition is met. If it’s a simple condition then it will be far more efficient and easier to use the Loop field (which will be covered in a future section.)

If you’re not sure whether to use OnDone or OnComplete in a particular instance then you should probably use OnComplete. OnComplete will always execute (unless you set SequenceInstance.SupressOnCompleteCallbacks to true)