-
Notifications
You must be signed in to change notification settings - Fork 13
VirtualImpacts
Virtual Impacts is a system that eases the handling of Sending Events to Visual Effects in the Scene.
The system handles the following:
- control the spawn/destroy of these effects
- create virtual impacts from a pool,
- manage impact lifecycle, and destroy impacts on end of lifetime
- send events to the vfx at creation/destruction with impact information
- compute minimal bounds from the active impacts.
It provides a simple API to handle all these.
VIRTUAL-IMPACTS.mp4
NOTE : To demonstrate usage, you can install a sample into your project from the package manager.
IMPORTANT : The virtual impacts cannot be previewed in editor non-playing mode.
In order to use Virtual Impacts, you need to prepare two things:
- A Visual Effect Assset that will receive Events from the Virtual Impact, and optionally a prefab referencing this Visual Effect Asset if it relies on property binders, output event helpers, etc.
- A VFX Virtual Impact Asset, created using the Create Asset Menu :
Visual Effects/VFX Virtual Impact
At runtime, you can use an API to spawn impacts, based on VFX Virtual Impact assets used as reference:
-
Before use, any virtual impact need to be initialized and its game object spawned. To initialize a virtual impact you need to use the static method
VFXVirtualImpact.CreateVirtualImpact(VFXVirtualImpact virtualImpact);
Only one instance of a virtual impact can exist at a time. -
Once Created, you will be able to request one impact from the pool, (if any available) using
bool VFXVirtualImpact.TryGetImpact(VFXVirtualImpact virtualImpact, out VFXVirtualImpact.Impact impact)
. You will then be able to configure the output object, and then spawn the impact. -
To spawn the impact use the
VFXVirtualImpact.Impact.Spawn(float lifetime)
methode on the created impact. Lifetime corresponds to the life of the impact, it requires to be greater than zero. -
After all use, virtual impacts must be disposed, and the game object destroyed. To dispose a virtual impact you need to use the static method
VFXVirtualImpact.DisposeVirtualImpact(VFXVirtualImpact virtualImpact);
Visual Effects affected by Virtual Impacts will receive Events alongside VFXEventAttribute payloads. In their default state, they shouldn't spawn anything, but instead wait for an event to start spawn contexts. Also, an event can be sent when a source is terminated.
VFX Virtual Impact allows implicitly to forward 3 different attributes by default:
-
float lifetime
: the lifetime of the impact -
vector3 position
: the position of the impact -
vector3 size
: the size of the bounds of the impact
Virtual Impact Assets define Visual Effect Graphs that are managed by the Virtual Impact System, you can either reference a Visual Effect Asset, or a Prefab containing at its root a Visual Effect component, alongside other components (for instance if using output event helpers, configured instance, or property binders)
- Asset : The visual
To visualize the current Virtual Impact instances, you can use the Virtual Impact debug window.
- Blocks and Features
- Other Runtime Features