Activator Logic Tutorial
Overview
This tutorial will demonstrate how to use Activators to mimic this incredibly simple code:
bool x = true; A() { if (x) { B(); } } C() { x = false; } B() { // Do arbitrary Activator things here }
In other words, it allows you to use an activator (C) to turn off another an activator (B) such that it won't execute its changes when called by third activator (A). From this, more advanced logic could be built, allowing for NAND gates etc.
Caveats
(for there are many).
- This has been tested on IntruderMM 2.08, but this behaviour may all be subject to change in future versions. YMMV.
- This was tested on an old map which may not have upgraded the to the latest IntruderMM package correctly (as will be seen later with weirdness to do with legacy-style animations). YMMV.
- This has not been tested in a published map, and it's possible that it will behave differently outside of editor testing map instances. YMMV.
Core Problem And Solution
It's often useful to chain activators one-into-another as shown below. This can be handy for many reasons, such as timing events to trigger after an interval using the Activator -> Options -> Delay
setting.
One might expect that turning off the GameObject an Activator is on might prevent its code from running when called this way. Unfortunately, it does not and the Activate()
call still runs even when disabled. This makes it very difficult to disable Activators and break chains of Activator-into-Activator logic in a convenient way, and prevents any sort of more complex logic based on stored state.
What is shown below is a tedious and somewhat finnicky workaround to this issue, relying on the fact that the Animation component does not run animations when disabled. This allows us to trigger an Activator as an Animation Event on the first frame of an animation, play the animation instead of directly calling Activator.Activate()
, and then enable/disable the object to block the Animator (and thus the Activator).
Setup
Create a prefab of an empty GameObject, and add an Activator and an Animation component.
Then, in your Assets (presumably in the same folder as the prefab you just created), create an Animation.
Warning: This next step may be inaccurate. At time of writing, it appears that modern Unity animations don't seem to work properly in Intruder. This may be a quirk of the current version, or it might be an issue with the IntruderMM in the project this was tested in. In any case, it will likely be necessary to set the animation to Legacy mode.
Select the newly-created animation and rename it something sensible (e.g. TriggerActivator.anim
. Then, right click on the tab of the Inspector window and toggle it to Debug mode.
Ensure the animation settings are set up as shown, and then turn off Debug mode.
Make sure you have your prefab open in the Hierarchy pane, and then open the Animation pane by double-clicking your .anim
asset in the Project pane, or through Window -> Animation -> Animation
. Select the GameObject in your prefab in the Hierarchy pane so that the animation pane knows that that's what we're animating.
Add a property (e.g. Transform.Position) and add keyframes at the start and end. In this example I simply move the Position.y from 0 to 1; it may not be necessary to add this movement, but I encountered some weird behaviour where Unity didn't seem to generate samples or run the animation if no properties were changed.
Then, at sample 0, click the 'Add an Event' button (circled in red below). In the Inspector, set this to trigger Activate()
, meaning that the event will trigger the Activator on the first frame it runs.
Save the animation, and drag it into the Animations list of the Animation component on your prefab, as shown above. Double-check that Activator -> Options -> Triggerable By Default
is turned on. Save the prefab.
Use
You can use this prefab wherever you need this toggleable functionality, and it can be enabled and disabled using another activator's Objects to Enable/Disable list.
Then, to trigger the activator from another activator, call the animation as shown: