Give Page Feedback | API

Component Managers - Event Subscription

The Component Manager contains some handy mechanisms for subscribing to a few Active Grid Events in a more intuitive manner than simply subscribing to these events directly via Active Grid references.

Agnostic Subscriptions

In some situations, you might care about an Active Grid related event but not necessarily which Active Grid is triggering the event. Using the Component Manager, you can subscribe in a way that lets you receive notification about the event from any Active Grid, which is an incredibly powerful feature.

In addition, you can filter the events by Grouping so that you only receive events for a particular type of Asset (such as Terrain).

Subscribe By World

In some situations, you might want to know when an Active Grid synced to a particular World fires a particular event. The Component Manager subscription methods give you a mechanism for doing just that. This is especially useful for situations where the World might have multiple Active Grids synced to it; rather than subscribe to the event on each Active Grid, you can subscribe once via the Component Manager, using the World ID as a filter.

This is also useful if the Active Grids that are synced to the World change at runtime, as there is no need to unsubscribe from the old Active Grid(s) and subscribe to the new one(s). Everything is handled automatically by the Component Manager.

Okay, Okay, Cool! But What Events Are We Talking About?

Currently, only two events on the Active Grid class are available to be subscribed to via the Component Manager, the CellPlayerIsInChanged and ActiveGridMoved events. These events have been chosen because they are good candidates for agnostic and world based subscriptions (especially CellPlayerIsInChanged).

SubscribeToCellPlayerIsInChangedEvents API

SubscribeToActiveGridMovedEvents API

Note that just like normal subscriptions, every Subscribe call must be paired with an Unsubscribe call (UnsubscribeToCellPlayerIsInChangedEvents and UnsubscribeToActiveGridMovedEvents)!

Can You Give Me A Hint On How This Might Be Used?

Of course! The Distance Based Pooling Chunk Manager actually uses these mechanism, so let's examine it to see how your own solutions might operate.

In case you don't know anything about the Distanced Based Pooling Chunk Manager, for each LOD Group that uses it, it tracks the Cell the Player is currently in to determine how far away Cells it is currently pooling are from it. Once Pooled Cells are a certain distance away from the Cell the Player is in, those Pooled Cells (and there Asset Chunks) are unloaded from the scene, freeing up memory.

Easier said than done, because the Chunk Manager doesn't actually have a way to know which Cell the Player is in. It needs an Active Grid for that! While we could force the developer to assign Active Grids in the inspector, such methods would be prone to errors. Instead, we can use the mechanism described in this Section!

Each LOD Group that uses the Chunk Manager is associated with a specific World and World Grouping. Using this information, the Chunk Manager is able to subscribe (via the Component Manager) to events from any and all Active Grids that are synced to these LOD Groups, and that are coming from the correct Grouping.

Another useful scenario is with logging. You might want to log when any event occurs, not caring which Active Grid initiated the event.