public sealed partial class ActiveGrid : MonoBehaviour, IIdentifiable, IWorldUser
The Active Grid is the collection of cells which are currently "active" in the scene,
as determined by your players position in
the scene. Like the World, the Active Grid can have 1 or more Groupings, each with
their own grid, which form a direct connection with the World Groupings
on the World the Active Grid is synced to.
>Note, however, it is not necessary to have an equal number of Groupings on the Active
Grid and World.
If the Active Grid has less groupings, then some groupings from the World will never
be loaded (unless they are loaded via other Active Grids or
World Regions).
If the Active Grid has more groupings, then the cells from the additional groupings
will be updated but won't actually result in World Cells
being loaded. It should be noted that since the Active Grid is actually made up of
1 or more grids, "Active Grids" may be a more accurate name for the class.
The behavior described above allows the Active Grid to be used with different Worlds
with different numbering of Groupings. Syncing to a new
World can result in some Groupings that were not being used previously to start being
used, and vice versa.
Typically, active cells are passed to the World so that it can choose to load any
associated World Cells, however it is possible to have
active cells that are not passed to the World (by disabling Update World on the Grouping),
though the use cases for that are limited.
An Active Grid should only be disabled (or the game object the component is on disabled)
if it is being
used as a prototype to create Active Grids
at runtime. Do not disable an Active Grid with the intention of enabling/using it
at a later time, as this will not work properly. Instead, you should create the Active
Grid via the
Component Manager's
CreateNonPersistentActiveGrid
method when it is needed, and destroy it via the
DestroyActiveGrid or
DestroyActiveGridAndWaitForCellUsersToBeRemoved
methods when it is no longer needed.
Name | Type | Description |
---|---|---|
ActiveGroupings | int |
Gets the number of active groupings, which is dependent upon the number of groupings on the World the Active Grid is currently synced to. If you want to know the number of groupings that are configured on the Active Grid (via the inspector), use ConfiguredGroupings property instead. |
ConfiguredGroupings | int |
Gets the number of groupings configured on the Active Grid via the inspector. This may be different than the number of ActiveGroupings, which is dependent upon the World the Active Grid is currently synced to. |
CreatedAtRuntime | bool |
Gets a value indicating whether the Active Grid was created at runtime. If false, it means the Active Grid was added in the inspector by the dev (not as a prototype). |
ID | int |
Gets the identification number of the Active Grid. |
IsActiveGridPersistent | bool |
Gets a value indicating whether the Active Grid is persistent between game sessions. Note, non prototype Active Grids added in the editor are always persistent. |
IsBusy | bool |
Gets a value indicating whether the Current Active Grid is busy. "Busy" simply means a multi frame action (aka, a coroutine method) is currently being executed (such as the method TryMovePlayerToLocation). |
IsInitialized | bool |
Gets a value indicating whether the Active Grid has been initialized. The Grid is initialized automatically by the Component Manager when it is initialized. |
LoadingBlueprintRepository | LoadingBlueprintRepository |
Gets the Loading Blueprint Repository assigned to this Active Grid. |
Player | IPlayer |
Gets the Current Player associated with the Active Grid. |
PlayerMover | PlayerMover |
Gets the Current Player Mover associated with the Active Grid. |
PlayerReadyToBeMoved |
During an Active Grid operation where the player needs to be moved and
true was passed in for waitForCommandBeforeMovingPlayer, this can be used to
determine whether the player is ready to be moved. This will be true if the area
the player is being moved to has successfully been loaded.
|
|
WorldSyncedTo | World |
Gets the Current World the Active Grid is synced to. |
public void AllowGridToRecenterWorldWhenSynced()
Allows the grid to recenter the World it is synced to by triggering an Origin Cell
changes in the World.
This only has an effect when the grid is synced to a World with 'Allow Active Grid
Re-Centering' enabled.
public bool AreActiveGridMovedEventsEnabledForGrouping(int groupingIndex)
Queries whether a particular World Grouping will fire events whenever the active grid on that grouping moves.
Name | Type | Description |
---|---|---|
groupingIndex | int |
The grouping to query. |
bool
True if events are enabled, false otherwise.
public bool ArePlayerCellChangeEventsEnabledForGrouping(int groupingIndex)
Queries whether a particular World Grouping will fire events whenever the cell the player is in changes on that grouping.
Name | Type | Description |
---|---|---|
groupingIndex | int |
The grouping to query. |
bool
True if events are enabled, false otherwise.
public int GetDistanceFromInnerAreaOfGrid(Cell cellOnEndlessGrid, int groupingIndex = 1)
Gets the distance that a cell is from the inner area of the active World Grouping
specified
(if no grouping is specified, uses Grouping 1).
You can use this info for a variety of purposes, for instance you could modify
loaded terrains to use a lower resolution
at runtime if they are farther from the grids center (although it would be better
to use a loading blueprint that
makes use of LODs for this purpose).
Name | Type | Description |
---|---|---|
cellOnEndlessGrid | Cell |
The cell whose distance from the inner area you want. It should be one based and a cell on your Worlds Endless Grid. |
groupingIndex | int |
The index of the World Grouping whose inner area you want to check the input cells distance against (optional). |
int
0 will be returned if the cell is part of the inner area, otherwise the distance is
based on a ring design, i.e., if the cell is in the first "ring" around the inner
area,
the distance will be 1,
second ring distance = 2, and so on.
Type | Condition |
---|---|
InvalidOperationException | Thrown if the method is called before the Active Grid has been initialized. |
public int GetDistanceFromInnerAreaOfGrid(WorldCell worldCell)
Gets the distance that a World Cell is from the inner area of the active grid associated
with the same grouping as the World Cell.
This effectively tells you what ring the cell is in
when using an outer ring grid or how far the cell is from
cell the player is standing on when using a sectioned grid.
You can use this info for a variety of purposes, for instance you could modify loaded
terrains to use a lower resolution at runtime if they are farther from the grids center.
Name | Type | Description |
---|---|---|
worldCell | WorldCell |
The World Cell whose distance from center you want. |
int
0 will be returned if the cell is part of the inner grid, 1 if the cell
is in the first ring around the inner grid, and so on.
Type | Condition |
---|---|
InvalidOperationException | Thrown if the method is called before the Active Grid has been initialized. |
public LoadingBlueprint GetLoadingBlueprintOfGrouping(int groupingIndex)
Gets the Loading Blueprint associated with a specific World Grouping.
Name | Type | Description |
---|---|---|
groupingIndex | int |
The World Grouping whose Loading Blueprint you are trying to get. |
LoadingBlueprint
The loading blueprint associated with the World Grouping.
Type | Condition |
---|---|
InvalidOperationException | Thrown if the method is called before the Active Grid has been initialized. |
public void GetRegisteredActiveCells(int groupingIndex, ICollection<LODCell> cells, bool clearCollectionIfNotEmpty)
Fills the input cells collection with all currently registered active LOD Cells associated with the input World Grouping. These are the Cells the Grouping has registered itself as a user of with the World.
Name | Type | Description |
---|---|---|
groupingIndex | int |
The index of the World Grouping whose active cells you want to get. |
cells | ICollection<LODCell> |
A container for storing the currently active cells. The container can be a lists, hashset, or any other collection that implements ICollection<LODCell> |
clearCollectionIfNotEmpty | bool |
Whether the cells collection should be cleared if it is not already empty, before adding the active cells. |
public bool HasCellsRegistered(int groupingIndex)
Gets a value indicating whether Active Grid Grouping specified is currently registered
as a
user of a set of Cells. In most cases, so long as
IsUpdatingWorld
returns true, this should also
return true, however there are situations where temporarily the Grouping may not be
registered as a
user of any Cells, even though IsUpdatingWorld returns true.
To be registered as a user of a set of Cells simply means that the Grouping has notified
the World
that those Cells are in use. This may or may not result in equivalent World Cells
being loaded,
depending on if there are other users of the same Cells but of a higher quality LOD.
To be honest, it's not clear how this information might be useful to you, but it's
there if you need it.
Name | Type | Description |
---|---|---|
groupingIndex | int |
The index of the World Grouping you are inquiring about. The World Grouping corresponds to a World Grouping on the World this Active Grid is synced to. |
bool
True if the cell users are loaded for the World Grouping specified, false otherwise.
public void InitiatePendingMove()
Tells a pending move operation that it is okay to proceed. This is used in conjunction
with passing in true
for the waitForCommandBeforeMovingPlayer parameter of the
TryMovePlayerToLocation and
TryMovePlayerToLocationOnNewWorld
methods.
This allows you to gain greater control over when the move operation is executed,
which is useful in many situations, such as
situations where you need to perform some logic before the player can be moved successfully.
In order to use this strategy correctly, you should query the PlayerReadyToBeMoved
property and wait for it to return true. Once
it returns true, indicating that the player is ready to be moved, you should perform
whatever logic you need to in order to
ensure the player move operation is successful. Once that logic is performed, call
this method and the Active Grid will then
care out the actual move operation, using the PlayerMover (if assigned), or directly
setting the IPlayer.Position property (if
no PlayerMover is assigned).
public bool IsAutoTrackingEnabled(int groupingIndex)
Gets a value indicating whether the Player's position is being automatically tracked
in
order to update the grid of Cells used by the specified grouping on this Active Grid.
With Auto Tracking disabled, the Cells for the grouping will be set based on the
initial position of the player, but will never be updated afterwards. Therefore, it
is rare that you would want
to disable Auto Tracking!
Note that in order for actual World Cell's and Asset Chunks to be loaded, 'Update
World'
must also be enabled for the grouping specified.
Name | Type | Description |
---|---|---|
groupingIndex | int |
The index of the World Grouping you are inquiring about. The World Grouping corresponds to a World Grouping on the Streamable Grid this Active Grid is synced to. |
bool
True if auto tracking is enabled, false otherwise.
public bool IsUpdatingWorld(int groupingIndex)
Gets a value indicating whether the World the Active Grid is sycned to will be updated based on the current grid of Cells on the grouping specified. In order for the World to load World Cells, which in turn loads Asset Chunks, updating must be enabled. Therefore, this method is mostly useful if you are not seeing Asset Chunks loaded in your scene and you're not sure why. This value may be false (and thus no Asset Chunks loaded on this grouping of the World) if you have created the Active Grid at runtime and not called one of the TrySetIfWorldShouldBeUpdated methods, or if you have called one of the TrySetIfWorldShouldBeUpdated methods and passed in false.
Name | Type | Description |
---|---|---|
groupingIndex | int |
The index of the World Grouping you are inquiring about. The World Grouping corresponds to a World Grouping on the World this Active Grid is synced to. |
bool
True if the World is being updated about the active grid cells for the layer, false
otherwise.
public void PreInitialize_SetLoadingBlueprintByID(int groupingIndex, int loadingBlueprintID, bool overwriteLoadingBlueprintFromPersistentData)
Changes the Loading Blueprint used by Active World Grouping indicated, allowing for the initial
blueprint to be different than what it normally is. This method is recommended over
the other PreInitialize_SetLoadingBlueprint... methods as the ID is more consistent
(names can
be changed and the Blueprint Index may change as a result of Blueprints being removed,
but the ID will remain the same forever unlesss the Blueprint itself is removed).
The main use of this will be to implement custom loading rather than making use of
the automatic IPersistentDataController class, if you need to save
different data in different places (on the server, on a file on the users system,
etc.). Note, if all your data is stored in the same place, you are
better off using a custom class that derives from IPersistentDataController, and then
set it up to save data to that location.
This must be called before the Active Grid has been initialized.
Name | Type | Description |
---|---|---|
groupingIndex | int |
The index of the active World Grouping to change. |
loadingBlueprintID | int |
The ID of the Loading Blueprint. This can be seen in the Loading Blueprint Repository Inspector, in the parentheses after the Blueprint Type. |
overwriteLoadingBlueprintFromPersistentData | bool |
Should the new loading blueprint you indicated overwrite the loading blueprint found in persistent data for this Active World Grouping (if any exist)? |
Type | Condition |
---|---|
InitializedSAMObjectException | Thrown when this method is called after the Active has been initialized. |
InvalidOperationException | Thrown if the ID does not correspond to a valid blueprint in the repository. |
public void PreInitialize_SetLoadingBlueprintByIndex(int groupingIndex, int loadingBlueprintIndex, bool overwriteLoadingBlueprintFromPersistentData)
Changes the Loading Blueprint used by Active World Grouping indicated, allowing for the initial
blueprint to be different than what it normally is.
The main use of this will be to implement custom loading rather than making use of
the automatic IPersistentDataController class, if you need to save
different data in different places (on the server, on a file on the users system,
etc.). Note, if all your data is stored in the same place, you are
better off using a custom class that derives from IPersistentDataController, and then
set it up to save data to that location.
This must be called before the Active Grid has been initialized.
Name | Type | Description |
---|---|---|
groupingIndex | int |
The index of the active World Grouping to change. |
loadingBlueprintIndex | int |
The index of the new loading blueprint to use. You can find this index by looking at the inspector of the Loading Blueprint Repository connected to this Active Grid (the only you assigned in this Active Grid's inspector). The index is found to the left of each loading blueprint name. |
overwriteLoadingBlueprintFromPersistentData | bool |
Should the new loading blueprint you indicated overwrite the loading blueprint found in persistent data for this Active World Grouping (if any exist)? |
Type | Condition |
---|---|
InitializedSAMObjectException | Thrown when this method is called after the Active has been initialized. |
IndexOutOfRangeException | Thrown if the index is not valid (less than 1 or greater than the number of blueprints in the respository) |
NullReferenceException | Thrown if the index points to a null blueprint, which should never happen. If it does, please contact me!! |
public void PreInitialize_SetLoadingBlueprintByName(int groupingIndex, string loadingBlueprintName, bool overwriteLoadingBlueprintFromPersistentData)
Changes the Loading Blueprint used by the Active World Grouping indicated,
allowing for the initial blueprint to be different than what it normally is.
The main use of this will be to implement custom loading rather than making use of
the automatic IPersistentDataController class, if you need to save
different data in different places (on the server, on a file on the users system,
etc.). Note, if all your data is stored in the same place, you are
better off using a custom class that derives from IPersistentDataController, and then
set it up to save data to that location.
This must be called before the Active Grid has been initialized.
Name | Type | Description |
---|---|---|
groupingIndex | int |
The index of the active World Grouping to change. |
loadingBlueprintName | string |
The name of the new loading blueprint to use. This must match one of the Loading Blueprints in the Loading Blueprint Repository connected to this Active Grid via the Active Grid's inspector. |
overwriteLoadingBlueprintFromPersistentData | bool |
Should the new loading blueprint you indicated overwrite the loading blueprint found in persistent data for this Active World Grouping (if any exist)? |
Type | Condition |
---|---|
InitializedSAMObjectException | Thrown when this method is called after the Active Grid has been initialized. |
InvalidNameException | Thrown if the name does not correspond to a valid loading blueprint on the repository. |
public void PreInitialize_SetPlayer(Transform newPlayer, PlayerMover newPlayerMover, bool overrideIgnorePlayerPositionInPersistentData, bool ignorePlayerPositionInPersistentData = false)
Sets the player that the Active Grid will track in order to perform shifts (both normal shifts and origin resetting). You must call this method before the Active Grid is initialized. While the Player's positional data will be saved with SAM's save data (so long as this Active Grid is persistent), the actualy Player object will not, as there is no way to save the reference. As such, you need to call this method each session.
Name | Type | Description |
---|---|---|
newPlayer | Transform |
The player transform to set. |
newPlayerMover | PlayerMover |
The player mover object associated with the player. This is only used with origin resetting to avoid physics issues when moving the player, therefore it can be left null if no special handling needs to take place when modifying the player position. Note that even if you have a Player Mover assigned via the Active Grid inspector, it will be overriden with this value, even if the value is null. |
overrideIgnorePlayerPositionInPersistentData | bool |
By default, the Player's position (which is always saved with SAM save data when the
Player is linked to a persistent Active Grid)
is loaded in with SAM's save data and used to position the Player. The Active Grid
has an option that you can set in its Inspector called
"Ignore Player Position In Persistent Data" which counters this behaviour, in situations
where it would be problematic to let
SAM set the Player Position.
|
ignorePlayerPositionInPersistentData | bool |
If overrideIgnorePlayerPositionInPersistentData is true, this value is used to determine whether the Player's positional data stored in SAM's persistent save data will be ignored. The value you set is used only for this session, so for each new session where you call this method, you should pass in the same value. See the info for overrideIgnorePlayerPositionInPersistentData for more information. |
Type | Condition |
---|---|
InitializedSAMObjectException | Thrown when this method is called after the Active has been initialized. |
InvalidOperationException | Thrown when null is passed in for newPlayer. |
public void PreInitialize_SetPlayer(IPlayer newPlayer, PlayerMover newPlayerMover, bool overrideIgnorePlayerPositionInPersistentData, bool ignorePlayerPositionInPersistentData = false)
Sets the player that the Active Grid will track in order to perform shifts (both normal
shifts and
origin resetting). You must call this method before the Active Grid is initialized.
While the Player's positional data
will be saved with SAM's save data (so long as this Active Grid is persistent), the
actualy Player object will not, as
there is no way to save the reference. As such, you need to call this method each
session.
With this method, you can pass in a class deriving from CustomPlayer, or any other
class that implements the IPlayer interface. These
types can be used in systems where the Player is not associated with the traditional
Transform component. These types of players
are especially useful when you want to use doubles to track player position data.
Name | Type | Description |
---|---|---|
newPlayer | IPlayer |
The player to set. |
newPlayerMover | PlayerMover |
The player mover object associated with the player. This is only used with origin resetting to avoid physics issues when moving the player, therefore it can be left null if no special handling needs to take place when modifying the player position. Note that even if you have a Player Mover assigned via the Active Grid inspector, it will be overriden with this value, even if the value is null. |
overrideIgnorePlayerPositionInPersistentData | bool |
By default, the Player's position (which is always saved with SAM save data when the
Player is linked to a persistent Active Grid)
is loaded in with SAM's save data and used to position the Player. The Active Grid
has an option that you can set in its Inspector called
"Ignore Player Position In Persistent Data" which counters this behaviour, in situations
where it would be problematic to let
SAM set the Player Position.
|
ignorePlayerPositionInPersistentData | bool |
If overrideIgnorePlayerPositionInPersistentData is true, this value is used to determine whether the Player's positional data stored in SAM's persistent save data will be ignored. The value you set is used only for this session, so for each new session where you call this method, you should pass in the same value. See the info for overrideIgnorePlayerPositionInPersistentData for more information. |
Type | Condition |
---|---|
InitializedSAMObjectException | Thrown when this method is called after the Active has been initialized. |
InvalidOperationException | Thrown when null is passed in for newPlayer. |
public void PreInitialize_SetWorld(World world, bool overwriteWorldFromPersistentData)
Sets the initial World for the Active Grid to use. This must be called before the
Active Grid has been
initialized, and if the Active Grid is persistent, the world must also be persistent.
Note, this will not fire the ActiveGridSyncedToNewWorld event.
Name | Type | Description |
---|---|---|
world | World |
The world for the Active Grid to use. |
overwriteWorldFromPersistentData | bool |
If true, the passed in World will be used regardless of whether persistent data exist for the Active Grid. If false, the passed in world will be used if a) no persistent data exist for the Active Grid, or b) persistent data exist, but no world was found in the data (happens when active grid was synced to a non persistent world when data was saved). |
Type | Condition |
---|---|
InitializedSAMObjectException | Thrown when this method is called after the Active has been initialized. |
InvalidOperationException | Thrown when the Active Grid has already been initialized. |
public void ProhibitGridFromFromRecenteringWorldWhenSynced()
Stops this Active Grid from being able to trigger World Re-Centering in any Worlds it is synced to.
public void SetAutoTracking(bool autoTracking)
Sets Auto Tracking (true means enabled, false means disabled) for all Groupings on
the Active Grid
(note, tracking only takes place when the grid is synced to a World).
Auto Tracking enables the tracking of the player to determine if they cross
the inner area boundary of one or more Groupings on the Active Grid.
When the player crosses the boundary for a Grouping the cells of the Active Grid on
that Grouping
are dynamically updated based on the position
of the player. In addition, when 'Update World' is enabled on a Grouping, the Active
Grid updates the
same Grouping on the World it is synced to so that it can update its World Cells appropriately,
which effectively enables dynamic loading and world updates.
Name | Type | Description |
---|---|---|
autoTracking | bool |
Pass in true to enable auto tracking, or false to disable it. |
public void SetAutoTracking(bool autoTracking, int groupingIndex)
Sets Auto Tracking (true means enabled, false means disabled) for a single Groupings
on the Active Grid (note, tracking only
takes place when the grid is synced to a World).
Auto Tracking enables the tracking of the player to determine if they cross the inner
area boundary of the
Groupings on the Active Grid.
When the player crosses the boundary for the Grouping, the cells of the Active Grid
on that Grouping
are dynamically updated based on the position
of the player. In addition, when 'Update World' is enabled on the Grouping, the Active
Grid updates the
same Grouping on the World it is synced to so that it can update its World Cells appropriately,
which effectively enables
dynamic loading and world updates.
Name | Type | Description |
---|---|---|
autoTracking | bool |
Pass in true to enable auto tracking, or false to disable it. |
groupingIndex | int |
The index of the grouping whose auto tracking should be enabled or disabled. |
public IEnumerator<YieldInstruction> TryChangeLoadingBlueprintByID(int loadingBlueprintID, int groupingIndex, bool refreshWorld)
Tries to change the Loading Blueprint
of the indicated active World Grouping
(change persist between sessions if the Active Grid is persistent) and
optionally refreshes the World the Active Grid is synced to so it will be made up
entirely of the Asset Chunks
associated with the new loading blueprint (if there is overlap between the blueprints,
some chunks may remain after the refresh).
This method will throw an exception if the Active Grid is already busy, so you should
query the IsBusy property
to make sure it is not before calling this method.
Name | Type | Description |
---|---|---|
loadingBlueprintID | int |
The ID of the Loading Blueprint. This can be seen in the Loading Blueprint Repository Inspector, in the parentheses after the Blueprint Type. |
groupingIndex | int |
The grouping whose loading blueprint will be changed. |
refreshWorld | bool |
If true, the objects associated with the previous blueprint are completely unloaded,
and the objects related to
the new blueprint are loaded. If false, the objects will be refreshed the next time
the player crosses a loading
boundary or during a world origin reset. If no world is synced to the Active Grid,
this option will do nothing.
|
IEnumerator<YieldInstruction>
An IEnumerator<YieldInstruction> that can be iterated over or used as a coroutine.
See the
YieldInstruction page for more info.
Type | Condition |
---|---|
UninitializedSAMObjectException | Thrown when the method is called before the Active Grid has been initialized. |
InvalidOperationException | Thrown when the method is called when IsBusy is already true or if the ID does not correspond to a valid Blueprint in the Repository. |
NullReferenceException | Thrown if the index points to a null blueprint, which should never happen. If it does, please contact me!! |
public IEnumerator<YieldInstruction> TryChangeLoadingBlueprintByIndex(int loadingBlueprintIndex, int groupingIndex, bool refreshWorld)
Tries to change the Loading Blueprint
of the indicated active World Grouping
(change persist between sessions if the Active Grid is persistent) and
optionally refreshes the World the Active Grid is synced to so it will be made up
entirely of the objects
associated with the new loading blueprint (if there is overlap between the blueprints,
some objects may remain after the refresh).
This method will throw an exception if the Active Grid is already busy, so you should
query the IsBusy property
to make sure it is not before calling this method.
Name | Type | Description |
---|---|---|
loadingBlueprintIndex | int |
The index of the new loading blueprint. This index must correspond to a valid blueprint on the Loading Blueprint Repository connected to this Active Grid. |
groupingIndex | int |
The grouping whose loading blueprint will be changed. |
refreshWorld | bool |
If true, the objects associated with the previous blueprint are completely unloaded,
and the objects related to
the new blueprint are loaded. If false, the objects will be refreshed the next time
the player crosses a loading
boundary or during a world origin reset. If no world is synced to the Active Grid,
this option will do nothing.
|
IEnumerator<YieldInstruction>
An IEnumerator<YieldInstruction> that can be iterated over or used as a coroutine.
See the
YieldInstruction page for more info.
Type | Condition |
---|---|
UninitializedSAMObjectException | Thrown when the method is called before the Active Grid has been initialized. |
InvalidOperationException | Thrown when the method is called when IsBusy is already true. |
IndexOutOfRangeException | Thrown if the index is not valid (less than 1 or greater than the number of blueprints in the respository) |
NullReferenceException | Thrown if the index points to a null blueprint, which should never happen. If it does, please contact me!! |
public IEnumerator<YieldInstruction> TryChangeLoadingBlueprintByName(string loadingBlueprintName, int groupingIndex, bool refreshWorld)
Tries to change the Loading Blueprint of the indicated active World Grouping
(change persist between sessions if the Active Grid is persistent) and
optionally refreshes the World so it will be made up entirely of the objects
associated with the new loading blueprint (if there is overlap between the blueprints,
some objects may remain after the refresh).
This method will throw an exception if the Active Grid is already busy, so you should
query the IsBusy property
to make sure it is not before calling this method.
Name | Type | Description |
---|---|---|
loadingBlueprintName | string |
The name of the new loading blueprint. This name must correspond to a valid blueprint on the Loading Blueprint Repository connected to this Active Grid. |
groupingIndex | int |
The grouping whose loading blueprint will be changed. |
refreshWorld | bool |
If true, the objects associated with the previous blueprint are completely unloaded,
and the objects related to
the new blueprint are loaded. If false, the objects will be refreshed the next time
the player crosses a loading
boundary or during a world origin reset.
|
IEnumerator<YieldInstruction>
An IEnumerator<YieldInstruction> that can be iterated over or used as a coroutine.
See the
YieldInstruction page for more info.
Type | Condition |
---|---|
UninitializedSAMObjectException | Thrown when the method is called before the Active Grid has been initialized. |
InvalidOperationException | Thrown when the method is called when IsBusy is already true. |
InvalidNameException | Thrown if the name does not correspond to a valid loading blueprint on the repository. |
public IEnumerator<YieldInstruction> TryChangeLoadingBlueprintsByID(int[] loadingBlueprintIDs, int[] groupingIndexes, bool refreshWorld)
Tries to change the Loading Blueprint of the
active World Groupings identified in the groupingIndexes array. This method is effectively
the same as TryChangeLoadingBlueprintByID,
except it allows you to change the loading blueprint of multiple World Groupings at
once.
It is recommended to use this method over the other TryChangeLoadingBlueprints methods,
because the ID is more consistent than the Blueprint Names or
Indexes (names can be modified and Indexes decremented when other Blueprints are removed).
The ID will remain the same forever unless the Blueprint is removed from
the Repository.
This method will throw an exception if the Active Grid is already busy, so you should
query the IsBusy property
to make sure it is not before calling this method.
Name | Type | Description |
---|---|---|
loadingBlueprintIDs | int[] |
The IDs of the Loading Blueprints. These can be seen in the Loading Blueprint Repository Inspector, in the parentheses after the Blueprint Type. |
groupingIndexes | int[] |
An array of grouping indexes whose loading blueprints will be changed. |
refreshWorld | bool |
If true, the objects associated with the previous blueprints are completely unloaded,
and the objects related to
the new blueprints are loaded. If false, the objects will be refreshed the next time
the player crosses a loading
boundary or during a world origin reset. If no world is synced to the Active Grid,
this option will do nothing.
|
IEnumerator<YieldInstruction>
An IEnumerator<YieldInstruction> that can be iterated over or used as a coroutine.
See the
YieldInstruction page for more info.
Type | Condition |
---|---|
UninitializedSAMObjectException | Thrown when the method is called before the Active Grid has been initialized. |
InvalidOperationException | Thrown when the method is called when IsBusy is already true or if one of the ID's do not correspond to a valid Blueprint. |
NullReferenceException | Thrown if the index points to a null blueprint, which should never happen. If it does, please contact me!! |
public IEnumerator<YieldInstruction> TryChangeLoadingBlueprintsByIndex(int[] loadingBlueprintIndexes, int[] groupingIndexes, bool refreshWorld)
Tries to change the Loading Blueprint of the
active World Groupings identified in the groupingIndexes array. This method is effectively
the same as TryChangeLoadingBlueprintByIndex,
except it allows you to change the loading blueprint of multiple World Groupings at
once.
This method will throw an exception if the Active Grid is already busy, so you should
query the IsBusy property
to make sure it is not before calling this method.
Name | Type | Description |
---|---|---|
loadingBlueprintIndexes | int[] |
The indexes of the new loading blueprints. These indexes must correspond to a valid blueprint on the Loading Blueprint Repository connected to this Active Grid, and the length of the array must be the same as the groupingIndexes array (The loading blueprint index at array index 0 of loadingBlueprintIndexes is used for the World Grouping identified by array index 0 of groupingIndexes). |
groupingIndexes | int[] |
An array of grouping indexes whose loading blueprints will be changed. |
refreshWorld | bool |
If true, the objects associated with the previous blueprints are completely unloaded,
and the objects related to
the new blueprints are loaded. If false, the objects will be refreshed the next time
the player crosses a loading
boundary or during a world origin reset. If no world is synced to the Active Grid,
this option will do nothing.
|
IEnumerator<YieldInstruction>
An IEnumerator<YieldInstruction> that can be iterated over or used as a coroutine.
See the
YieldInstruction page for more info.
Type | Condition |
---|---|
UninitializedSAMObjectException | Thrown when the method is called before the Active Grid has been initialized. |
InvalidOperationException | Thrown when the method is called when IsBusy is already true. |
IndexOutOfRangeException | Thrown if the index is not valid (less than 1 or greater than the number of blueprints in the respository) |
NullReferenceException | Thrown if the index points to a null blueprint, which should never happen. If it does, please contact me!! |
public IEnumerator<YieldInstruction> TryChangeLoadingBlueprintsByName(string[] loadingBlueprintNames, int[] groupingIndexes, bool refreshWorld)
Tries to change the Loading Blueprint of the active World Groupings identified in
the groupingIndexes array. This method is effectively the same as TryChangeLoadingBlueprintByName,
except it allows you to change the loading blueprint
of multiple World Groupings at once.
This method will throw an exception if the Active Grid is already busy, so you should
query the IsBusy property
to make sure it is not before calling this method.
Name | Type | Description |
---|---|---|
loadingBlueprintNames | string[] |
The names of the new loading blueprints. These names must correspond to a valid blueprint on the Loading Blueprint Repository connected to this Active Grid, and the length of the array must be the same as the groupingIndexes array (The loading blueprint name at array index 0 of loadingBlueprintIndexes is used for the World Grouping identified by array index 0 of groupingIndexes). |
groupingIndexes | int[] |
An array of grouping indexes whose loading blueprints will be changed. |
refreshWorld | bool |
If true, the objects associated with the previous blueprints are completely unloaded,
and the objects related to
the new blueprints are loaded. If false, the objects will be refreshed the next time
the player crosses a loading
boundary or during a world origin reset. If no world is synced to the Active Grid,
this option will do nothing.
|
IEnumerator<YieldInstruction>
An IEnumerator<YieldInstruction> that can be iterated over or used as a coroutine.
See the
YieldInstruction page for more info.
Type | Condition |
---|---|
UninitializedSAMObjectException | Thrown when the method is called before the Active Grid has been initialized. |
InvalidOperationException | Thrown when the method is called when IsBusy is already true. |
InvalidNameException | Thrown if ones of the names does not correspond to a valid Blueprint. |
NullReferenceException | Thrown if the index points to a null blueprint, which should never happen. If it does, please contact me!! |
public IEnumerator<YieldInstruction> TryChangeOriginCellOfWorld(Cell newOriginCell, Vector3Double playerPositionAfterChange, bool setPlayerYPositionBasedOnTerrain = false, double playerYOffset = 1f, bool positionRelativeToOriginCell = false)
Tries to change the Origin Cell of the synced to World to the passed in newOriginCell
while moving the player to a new location in the World.
Unlike the World's ChangeOriginCell method, this method
offers more options for how the Player will be moved, allowing you to position the
player exactly as you want once the Origin Cell
change is complete.
However, the process of doing this is not as seamless as the normal Origin Cell change
process, as the current cells associated
with the player's current position are removed at the same time as new cells at the
new position are added; as such, it's very
likely the player will notice what's going on. As such, this method should only be
used with some kind of obfuscation technique to hide
what's happening in the game world from the player. At the very least, you should
usually disable the player's movement while the method is executing (to
keep them from falling through the world when the old cells are removed), however
this is up to you.
It should be noted that when the World's Origin Change Strategy is set to Duplicate
World, the method will only complete execution after the
old World Cells (and Asset Chunks) that used the previous Origin Cell are removed.
This is necessary to ensure the player is not re-activated while
lingering Assets are left in the scene, however it may throw off the timing of the
Player being moved. If this is a concern for you, you should switch
to using a World Shifter to perform the Origin Cell change.
The main purpose of this method is to allow you to change the player's position within
the game world while simultaneously
updating the Origin Cell of the world, in a manner that avoids asset chunks being
moved outside of the valid floating point range, which may cause
issues for your game. It's useful in situations where you can obfuscate the game world,
for instance imagine a Skyrim like fast travel system where a
loading screen is displayed when fast travel is used. If you need a method that doesnt
invovle obfuscating the game world, you will need to use a
combination of a manual World Cell Origin change via the World's
ChangeOriginCell method, followed by a call to this Active Grid's
TryMovePlayerToLocation. This technique will take longer
and the player and game world may temporarily travel outside the valid floating point
range, but unfortunately it is the only way to execute an
Origin Cell change and player movement in game, without obfuscating the game world.
Do note, if using the Duplicate World origin change strategy, you
will need to make sure to choose a new Origin Cell that doesn't result in overlap
between the new world cells (using the new Origin Cell) and the
old world cells (which are only removed after the new world is constructed).
Do note that this method will trigger a normal Origin Cell Change on the World, which
has the following consequences:
1) If a World Shifter is being used by the World and it is set to shift the Player's
position, it will do so as normal. Any movement
performed by this method will take place after, so the final position of the player
will be correctly set to whatever
you set here (assuming overridePostChangePlayerPosition is true).
2) Any IWorldUsers registered with the World will be notified of the Origin Cell Change,
and their appropriate callback methods will be invoked as
a result. This includes any Active Grids registered with the World, including the
one you call the TryChangeOriginCellOfWorld method with. When
overridePostChangePlayerPosition is true, however, the Active Grid will not move the
player within its Origin Cell Changed callback methods,
even when Move Player After Origin Cell Change is enabled, as doing so would be redundant.
With that said, it is very likely to be impossible to keep the player from noticeing
the processing of the
Origin Cell change, and as such it usually is a good idea to obscure the world in
some way while the
origin update is in progress, with a loading screen or some kind of visual effect.
There are also options to manually move the player with this method, however this
move will be carried out through a simple
IPlayer.Position set operation rather than using the Player Mover (if attached), and
will be performed after the
player position is shifted during the Origin Cell Change operation.
In situations where you are not using a loading screen, it may make more sense to
utilize the
TryMovePlayerToLocation
method instead, as there is less disruption to the currently loaded World Cells, and
so
the player should not notice the world being updated during
the move process. Note, however, if you are using an exceptionally large world, moving
the player to a location very far
from the origin may not be possible due to floating point issues, in which case this
Origin Cell change method will need
to be used instead.
Name | Type | Description |
---|---|---|
newOriginCell | Cell |
The Endless Grid Cell which will become the Origin Cell of the World the Active Grid is currently synced to. Note, this can be a cell with indexes outside the range of the Streamable Grid this Active Grid is synced to if using an endless world. |
playerPositionAfterChange | Vector3Double |
If movePlayerAfterChange is true, the player will be moved to this location. The location can either be an absolute position in the scene, or a position relative to the new Origin Cell. You can control which behaviour is used using the positionRelativeToOriginCell argument. |
setPlayerYPositionBasedOnTerrain | bool |
If movePlayerAfterChange and setPlayerYPositionBasedOnTerrain are true, the player's
y location will be
set based on the terrain whose bounds the player is within (i.e, the y location in
playerPositionAfterChange
will be ignored).
|
playerYOffset | double |
If movePlayerAfterChange and setPlayerYPositionBasedOnTerrain are true,
you can pass in an offset value which will be added to the player's calculated
position (based on the terrain). This is necessary since setting the player's
y position to the calculated position would likely cause the player to
overlap the terrain, which is not ideal.
|
positionRelativeToOriginCell | bool |
Is the playerPositionAfterChange relative to scene space (false) or the new Origin
Cell (true). If
setPlayerYPositionBasedOnTerrain is false, this also dictates whether the y value
of
playerPositionAfterChange is relative to the WorldSyncedTo or Origin Cell.
|
IEnumerator<YieldInstruction>
An IEnumerator<YieldInstruction> that can be iterated over or used as a coroutine.
See the YieldInstruction page for more info.
Type | Condition |
---|---|
InvalidOperationException | Thrown when a WorldSyncedTo is not associated with the grid, when the Active Grid has not been initialized yet, when this method is called while the Active Grid is busy executing a multi frame action (check IsBusy before calling ActiveGrid methods that begin with "Try"), when setPlayerYPositionBasedOnTerrain is true but the Current WorldSyncedTo does not use Unity Terrain or chunks are not enabled on the Active Grid, or when a player is not associated with the grid but movePlayerAfterChange is true. |
public IEnumerator<YieldInstruction> TryDesyncFromCurrentWorld()
Tries to de-sync the Active Grid from the World it is Currently synced to.
IEnumerator<YieldInstruction>
An IEnumerator<YieldInstruction> that can be iterated over or used as a coroutine.
See the
YieldInstruction page for more info.
Type | Condition |
---|---|
InvalidOperationException | Thrown when this method is called before the grid has been initialized or while the Active Grid is busy executing a multi frame action. Check IsBusy before calling ActiveGrid methods that begin with "Try". |
public IEnumerator<YieldInstruction> TryMovePlayerToLocation(Vector3Double location, bool waitForCommandBeforeMovingPlayer, bool waitForOldObjectsToBeRemoved, bool setPlayerYPositionBasedOnTerrain = false, double playerYOffset = 1f)
Tries to move the player associated with this Active Grid to the location specified.
This method fully loads the cells (and objects if necessary) around the target location
before
moving the player (this occurs over several frames).
Once loaded, if waitForCommandBeforeMovingPlayer is true, this method will yield until
InitiatePendingMove is called. If false, this method
will move the player immediately after the objects at the new location are loaded.
If waitForCommandBeforeMovingPlayer is true, you can query the PlayerReadyToBeMoved
property to make sure the
Active Grid has loaded the new area before calling InitiatePendingMove (otherwise,
there is no guarantee the player
will be moved immediately after calling InitiatePendingMove).
Depending on the PlayerMover
used by this Active Grid, the actual move operation may also take several frames.
This method, like all Try methods in this API, will throw an exception when
a coroutine operation is Currently being executed by this Active Grid.
The best way to account for this possibility is to simply
check to make sure the Active Grid is not busy before calling this move method, which
you can do by checking
the Active Grid's IsBusy property.
Name | Type | Description |
---|---|---|
location | Vector3Double |
The location to move the player to. |
waitForCommandBeforeMovingPlayer | bool |
If true, the new area that the player will be moved to will be loaded, but the actual move operation will be delayed until the InitiatePendingMove method is called. If false, the move will be performed immediately after the new area is loaded. |
waitForOldObjectsToBeRemoved | bool |
If true, the coroutine will not exit/yield break until the pre move objects that are
no longer needed are removed.
|
setPlayerYPositionBasedOnTerrain | bool |
If true, the y value in location will be ignored and the y position to move the player
to will be calculated based on the
height of the terrain at the location to move the player to. Only set this to true
if you know the Active Grid is synced
to a WorldSyncedTo that is using Terrains. If there is no terrain at the location,
the location's y value will be used.
|
playerYOffset | double |
When setPlayerYPositionBasedOnTerrain is true, this value can be used to ensure the
player does not overlap the terrain. A value of 1, for instance,
will place the player 1 unit above the terrain's height. You will need to experiment
to find the best value, as it will depend largely upon the
shape and height of your player's collider.
|
IEnumerator<YieldInstruction>
An IEnumerator<YieldInstruction> that can be iterated over or used as a coroutine.
See the
YieldInstruction page for more info.
Type | Condition |
---|---|
InvalidOperationException | Thrown when no player or WorldSyncedTo is associated with the grid, when the Active Grid has not been initialized yet, or when this method is called while the Active Grid is busy executing a multi frame action (check IsBusy before calling ActiveGrid methods that begin with "Try"), or when setPlayerYPositionBasedOnTerrain is true but the Current WorldSyncedTo does not use Unity Terrain or chunks are not enabled on the Active Grid. |
public IEnumerator<YieldInstruction> TryMovePlayerToLocationOnNewWorld(Vector3Double location, World newWorldToSyncTo, bool waitForCommandBeforeMovingPlayer, bool allowGridToRecenterWorld, bool waitForOldObjectsToBeRemoved, bool setPlayerYPositionBasedOnTerrain = false, double playerYOffset = 1f, int groupingWithTerrainToAlignPlayerTo = 1)
Tries to move the player associated with this Active Grid to the location specified
on the new World,
and if the move is successful, syncs the Active Grid to this new World.
This method fully loads the cells (and objects if necessary) around the target location
before
moving the player (this occurs over several frames).
Once loaded, if waitForCommandBeforeMovingPlayer is true, this method will yield until
InitiatePendingMove is called. If false, this method
will move the player immediately after the objects at the new location are loaded.
If waitForCommandBeforeMovingPlayer is true, you can query the PlayerReadyToBeMoved property to make sure the
Active Grid has loaded the new area before calling InitiatePendingMove (otherwise,
there is no guarantee the player
will be moved immediately after calling InitiatePendingMove).
Depending on the PlayerMover
used by this Active Grid, the actual move operation may also take several frames.
This method, like all Try methods in this API, will throw an exception when
a coroutine operation is currently being executed by this Active Grid.
The best way to account for this possibility is to simply
check to make sure the Active Grid is not busy before calling this method, which you
can do by checking
the Active Grid's IsBusy property.
Name | Type | Description |
---|---|---|
location | Vector3Double |
The location to move the player to. |
newWorldToSyncTo | World |
The new World to sync to. |
waitForCommandBeforeMovingPlayer | bool |
If true, the new area that the player will be moved to will be loaded, but the actual move operation will be delayed until the InitiatePendingMove method is called. If false, the move will be performed immediately after the new area is loaded. |
allowGridToRecenterWorld | bool |
If true, the grid will be permitted to force the World To re-center itself when the player crosses the re-centering boundary (assuming 'Allow Active Grid Re-Centering' is enabled on the World). |
waitForOldObjectsToBeRemoved | bool |
If true, the coroutine will not exit/yield break until the pre sync/move objects that
are no longer needed are removed.
|
setPlayerYPositionBasedOnTerrain | bool |
If true, the y value in location will be ignored and the y position to move the player
to will be calculated based on the
height of the terrain at the location to move the player to. Only set this to true
if you know
the newWorldToSyncTo uses Terrain. If there is no terrain at the location, the location's
y value will be used.
|
playerYOffset | double |
When setPlayerYPositionBasedOnTerrain is true, this value can be used to ensure the
player does not overlap the terrain.
A value of 1, for instance,
will place the player 1 unit above the terrain's height. You will need to experiment
to find the best value, as it
will depend largely upon the shape and height of your player's collider.
|
groupingWithTerrainToAlignPlayerTo | int |
The World Grouping on the new world that contains the terrain to align the player to. This is usually the base World Grouping (Layer 1) |
IEnumerator<YieldInstruction>
An IEnumerator<YieldInstruction> that can be iterated over or used as a coroutine.
See the
YieldInstruction page for more info.
Type | Condition |
---|---|
InvalidOperationException | Thrown when no player is associated with the grid, when the Active Grid has not been initialized yet, or when this method is called while the Active Grid is busy executing a multi frame action (check IsBusy before calling ActiveGrid methods that begin with "Try"), or when setPlayerYPositionBasedOnTerrain is true but the new WorldSyncedTo to sync to does not use Unity Terrain or chunks are not enabled on the Active Grid. |
public void TrySetIfWorldShouldBeUpdated(bool worldShouldBeUpdated)
Attempts to set the "Update World" property of all Groupings on the Active Grid. Pass
in true if you want all Groupings
to update the World the Active Grid is synced to, or false if you do not want them
to update the World.
With world upates enabled, the Active Grid will update the World on which cells are
loaded for each Active World Grouping.
It does this when the Active Grid is initially initilized (by sending the list of
cells that are initially
loaded on the World Grouping based on the player's initial position), and also when
the collection of cells tracked by
the Active Grid are updated dynamically as a result of the player moving across the
current inner area boundary of
each Active World Grouping (however, this only occurs if 'Enable Auto Tracking' is
enabled for each layer).
The inner area boundary is calculated using the Loading Blueprint used by the Active
World Grouping,
as well as the dimensions of the cells on the same World Grouping on the World the
Active Grid is sycned
to (more specifically, the Streamable Grid of the World Grouping).
This method will likely result in World Cells on the WorldSyncedTo to be loaded or
unloaded, however using this
by itself will not allow you to track when that happens. This method will also not
allow for the player to be
aligned to a Terrain when worldShouldBeUpdated. If you need player alignment to be
performed, or need to know
when the World Cells are loaded/unloaded as a result of Update World being set, you
should use the
TrySetIfWorldShouldBeUpdatedThenWaitForWorldUpdate
method instead.
Note that it's possible that the Active Grid has more groupings than the World it
is synced to. In this case, all groupings
on the Active Grouping are updated, even if the grouping does not have a corresponding
grouping on the World. In this way, if the
Active Grid becomes synced to a World with a new matching grouping, the value you
set will be applied to it.
Name | Type | Description |
---|---|---|
worldShouldBeUpdated | bool |
Whether the world should be updated for all Groupings of the Active Grid. |
Type | Condition |
---|---|
InvalidOperationException | Thrown if the Active Grid has not been initialized or if the method is called while the Active Grid is already busy. You should always check if the Active Grid is busy before calling any method that begins with Try! |
public void TrySetIfWorldShouldBeUpdated(bool worldShouldBeUpdated, int groupingIndex)
Attempts to set the "Update World" property of a single Grouping on the Active Grid.
Pass in true if you want the Grouping
to update the World the Active Grid is synced to, or false if you do not want it to
update the World.
With world upates enabled, the Active Grid will update the World on which cells are
loaded for the Active World Grouping.
It does this when the Active Grid is initially initilized (by sending the list of
cells that are initially
loaded on the World Grouping based on the player's initial position), and also when
the collection of cells tracked by
the Active Grid are updated dynamically as a result of the player moving across the
current inner area boundary of
the Active World Grouping (however, this only occurs if 'Enable Auto Tracking' is
enabled for the Layer).
The inner area boundary is calculated using the Loading Blueprint used by the Active
World Grouping,
as well as the dimensions of the cells on the same World Grouping on the World the
Active Grid is sycned
to (more specifically, the Streamable Grid of the World Grouping).
Name | Type | Description |
---|---|---|
worldShouldBeUpdated | bool |
Whether the world should be updated for the Grouping of the Active Grid. |
groupingIndex | int |
The index of the Grouping on the Active Grid whose "Update World" property will be set. |
Type | Condition |
---|---|
InvalidOperationException | Thrown if the Active Grid has not been initialized or if the method is called while the Active Grid is already busy. You should always check if the Active Grid is busy before calling any method that begins with Try! |
public IEnumerator<YieldInstruction> TrySetIfWorldShouldBeUpdatedThenWaitForWorldUpdate(bool worldShouldBeUpdated)
Attempts to set the "Update World" property of all Groupings on the Active Grid. Pass
in true if you want all Groupings
to update the World the Active Grid is synced to, or false if you do not want them
to update the World.
With world upates enabled, the Active Grid will update the World on which cells are
loaded for each Active World Grouping.
It does this immediately (by sending the list of cells that are currently
'loaded' on the Layer), and also when the collection of cells tracked by
the Active Grid are updated dynamically as a result of the player moving across the
current inner area boundary of
each Active World Grouping (however, this only occurs if 'Enable Auto Tracking' is
enabled for each layer).
The inner area boundary is calculated using the Loading Blueprint used by the Active
World Grouping,
as well as the dimensions of the cells on the same World Grouping on the World the
Active Grid is sycned
to (more specifically, the Streamable Grid of the World Grouping).
This method is the same as
TrySetIfWorldShouldBeUpdated,
except that the method will wait for the World the Active Grid is synced to to complete
a full update. This ensures that
the World Cells on the WorldSyncedTo associated with the cells of the Active Grid
are either loaded (when worldShouldBeUpdated
is true) or unloaded (when worldShouldBeUpdated is false). This allows you to wait
for the game world to either be
loaded (and in a playable state) or unloaded before continuing with some other action
(such as removing a loading screen).
In addition, when worldShouldBeUpdated is true and Align Player To Terrain is enabled
in the inspector of this
Active Grid, after waiting for a world update, the method will align the player to
the Terrain. This is not done
with the normal
TrySetIfWorldShouldBeUpdated
method, so if you need the player to be aligned to the Terrain, you must use this
coroutine method, regardless of
whether you care about waiting for a World update.
Name | Type | Description |
---|---|---|
worldShouldBeUpdated | bool |
Whether the world should be updated for all Groupings of the Active Grid. |
IEnumerator<YieldInstruction>
An IEnumerator<YieldInstruction> that can be iterated over or used as a coroutine.
See the
YieldInstruction page for more info.
Type | Condition |
---|---|
InvalidOperationException | Thrown if the Active Grid has not been initialized or if the method is called while the Active Grid is already busy. You should always check if the Active Grid is busy before calling any method that begins with Try! |
public IEnumerator<YieldInstruction> TrySetIfWorldShouldBeUpdatedThenWaitForWorldUpdate(bool worldShouldBeUpdated, int groupingIndex)
Attempts to set the "Update World" property of a single Grouping on the Active Grid.
Pass in true if you want the Grouping
to update the World the Active Grid is synced to, or false if you do not want it to
update the World.
With world upates enabled, the Active Grid will update the World on which cells are
loaded for the Active World Grouping.
It does this immediately (by sending the list of cells that are currently
'loaded' on the Grouping), and also when the collection of cells tracked by
the Active Grid are updated dynamically as a result of the player moving across the
current inner area boundary of
the Active World Grouping (however, this only occurs if 'Enable Auto Tracking' is
enabled for the Grouping).
The inner area boundary is calculated using the Loading Blueprint used by the Active
World Grouping,
as well as the dimensions of the cells on the same World Grouping on the World the
Active Grid is sycned
to (more specifically, the Streamable Grid of the World Grouping).
This method is the same as
TrySetIfWorldShouldBeUpdated,
except that the method will wait for the World the Active Grid is synced to to complete
a full update. This ensures that
the World Cells on the WorldSyncedTo associated with the cells of the Active Grid
are either loaded (when worldShouldBeUpdated
is true) or unloaded (when worldShouldBeUpdated is false). This allows you to wait
for the game world to either be
loaded (and in a playable state) or unloaded before continuing with some other action
(such as removing a loading screen).
In addition, when worldShouldBeUpdated is true, Align Player To Terrain is enabled
in the inspector of this
Active Grid, and the World Grouping passed in is the same layer assigned to the 'World
Grouping With Terrain To Align Player To'
field, after waiting for a world update, the method will align the player to the Terrain.
This is not done
with the normal
TrySetIfWorldShouldBeUpdated
method, so if you need the player to be aligned to the Terrain, you must use this
coroutine method, regardless of
whether you care about waiting for a World update.
Name | Type | Description |
---|---|---|
worldShouldBeUpdated | bool |
Whether the world should be updated for the Grouping of the Active Grid. |
groupingIndex | int |
The index of the Grouping on the Active Grid whose "Update World" property will be set. |
IEnumerator<YieldInstruction>
An IEnumerator<YieldInstruction> that can be iterated over or used as a coroutine.
See the
YieldInstruction page for more info.
Type | Condition |
---|---|
InvalidOperationException | Thrown if the Active Grid has not been initialized or if the method is called while the Active Grid is already busy. You should always check if the Active Grid is busy before calling any method that begins with Try! |
public IEnumerator<YieldInstruction> TrySyncToNewWorldAroundPlayer(World newWorldToSyncTo, bool allowGridToRecenterWorld, bool waitForOldObjectsToBeRemoved, bool setPlayerYPositionBasedOnTerrain = false, double playerYOffset = 1f, bool waitForCommandBeforeMovingPlayer = false, int groupingWithTerrainToAlignPlayerTo = 1)
Tries to sync to the new WorldSyncedTo at the player's Current position.
This method fully loads the cells (and objects if necessary) of the new WorldSyncedTo,
and then removes the
cells (and objects) of the old WorldSyncedTo.
This method, like all Try methods in this API, will throw an exception when
a coroutine operation is Currently being executed by this Active Grid.
The best way to account for this possibility is to simply
check to make sure the Active Grid is not busy before calling this method, which you
can do by checking
the Active Grid's IsBusy property.
Name | Type | Description |
---|---|---|
newWorldToSyncTo | World |
The new World to sync to. |
allowGridToRecenterWorld | bool |
If true, the grid will be permitted to force the World To re-center itself when the player crosses the re-centering boundary (assuming 'Allow Active Grid Re-Centering' is enabled on the World). |
waitForOldObjectsToBeRemoved | bool |
If true, the coroutine will not exit/yield break until the pre sync objects that are
no longer needed are removed.
|
setPlayerYPositionBasedOnTerrain | bool |
If true, once the new WorldSyncedTo is loaded, the y position of the player will be
adjusted to that of the terrain the player is on (plus the playerYOffset).
If a Player Mover exist on the Active Grid, it will be used to move the player.
|
playerYOffset | double |
When setPlayerYPositionBasedOnTerrain is true, this value can be used to ensure
the player does not overlap the terrain. A value of 1, for instance,
will place the player 1 unit above the terrain's height. You will need to experiment
to find the best value, as it will depend largely upon the
shape and height of your player's collider.
|
waitForCommandBeforeMovingPlayer | bool |
This variable only applies when setPlayerYPositionBasedOnTerrain is true, otherwise
the player will not be moved at all
and this variable will not be useful. When setPlayerYPositionBasedOnTerrain, this
controls whether the method should
wait for a manual move command before changing the player's y position. This move
command is supplied via the
InitiatePendingMove method, which you will
call.
|
groupingWithTerrainToAlignPlayerTo | int |
The World Grouping on the new world that contains the terrain to align the player to. This is usually the base World Grouping (Grouping 1) |
IEnumerator<YieldInstruction>
An IEnumerator<YieldInstruction> that can be iterated over or used as a coroutine.
See the
YieldInstruction page for more info.
Type | Condition |
---|---|
RequiredComponentNotFoundException | Thrown when a Player Transform has not been supplied to the Active Grid. |
InvalidOperationException | Thrown when no player is associated with the grid, when the Active Grid has not been initialized yet, when this method is called while the Active Grid is busy executing a multi frame action (check IsBusy before calling ActiveGrid methods that begin with "Try"), or when setPlayerYPositionBasedOnTerrain is true but the new WorldSyncedTo to sync to does not use Unity Terrain or chunks are not enabled on the Active Grid. |