One fundamental limitation of UltEvents is that the target cannot be changed dynamically.

Sure we can run GetComponent - but we can’t actually use the output as a target


To work around this limitation, the UltSwapping framework was devised. ‘UltSwap’ is a term used to describe logic that’s able edit the event and swap out the target.

The ‘Swapped’ Ult Event Holder originally contains logic that runs on the ‘Dummy’ Rigidbody. When the swap is ran, the Swapped Ult Event Holder is programmatically ‘swapped’ to use an entirely different return value.

The UltSwap Prefabs

Here is an overview of the main Prefab:

  • UltSwap - When ran, it will edit the ‘Swapped’ GameObject, and replace its ‘Dummy’ target with another one.
  • Swapped - Contains the logic you want to swap the target out on.
  • Dummy - Contains any dummy components you want to be swapped for the real target.
  • SwapSource - Holds the target you want to swap the dummy out for.
  • ReferenceHolder - Used internally by the UltSwap system, and allows for multiple swaps.

The UltSwapFromParent has the same hierarchy. The difference is that it contains extra logic for performing the swap on whatever you parent it to, rather than you manually providing the swap source.

Samples - Zero Gravity Crate Spawner

UltSwapping allows us to directly use the GameObject that we’re provided inside of an OnSpawnEvent:

CrateSpawner (Gym Cube 1x1) Swapped (GetComponent) Swapped (Disable Gravity)

  1. We set the swap source to the GameObject argument - this is the GameObject of whatever is spawned.
  2. We Invoke the UltSwap to change the Dummy GameObject used by our logic on the Swapped GameObject out for what the Crate Spawner provided.
  3. We finally Invoke the Swapped GameObject to run our un-dummified logic.

The first swap gets the Rigidbody from our spawnable, and then feeds it into the 2nd swap which simply disables its gravity.

Using Ult Utils to create an UltSwap

The Ult Utils package allows you to generate an Ult Swap for a component in a few clicks via the Inspector: