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 |
---|---|---|
ConfiguredGroupings | int |
Gets the number of groupings configured on the Active Grid via the inspector. This may be different than the number of SyncedGroupings, 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.
|
|
SyncedGroupings | int |
Gets the number of synced groupings, which is dependent upon the number of groupings
on the World the Active Grid is
currently synced to that could be matched (by Grouping Name) to Groupings on this
Active Grid.
|
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 ArePlayerCellChangeEventsEnabledForGrouping(int activeGridGrouping)
Queries whether a particular Active Grid Grouping will fire events whenever the cell the player is in changes on that grouping.
Name | Type | Description |
---|---|---|
activeGridGrouping | int |
The index of the Active Grid Grouping you are inquiring about, as shown in the Active Grid inspector. |
bool
True if events are enabled, false otherwise.
public int GetDistanceFromInnerAreaOfGrid(Cell cellOnEndlessGrid, int zoneIndex, DistanceCheckMethod distanceCheckMethod, int activeGridGrouping = 1)
Gets the distance that an endless grid cell is from the inner area of the Active Cells
of the specified Active
Grid Grouping 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).
Note that if you are not sure whether the Active Grid Grouping is currently synced
to a World Grouping, you should place
the calling code in a try/catch statement and look for a InvalidOperationException.
When this exception is thrown, you can
disregard it and exit whatever code is trying to use the distance.
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 World's Endless Grid. |
zoneIndex | int |
The index of the Zone, which will be used to find the correct Inner Area to perform the Distance check with. |
distanceCheckMethod | DistanceCheckMethod |
The method used to calculate the distance. |
activeGridGrouping | int |
The index of the Active Grid Grouping you are inquiring about, as shown in the Active Grid inspector. |
int
0 will be returned if the cell is part of the inner area, otherwise the distance of
the cell's row, column, and layer (if 3D) from the
Inner Area are computed separately, and the largest distance is returned.
Type | Condition |
---|---|
UninitializedSAMObjectException | Thrown if the method is called before the Active Grid is initialized. |
InvalidOperationException | Thrown if the method is called for an Active Grid Grouping that is not synced to a World Grouping. |
public int GetDistanceFromInnerAreaOfGrid(WorldCell worldCell, DistanceCheckMethod distanceCheckMethod)
Gets the distance that a World Cell is from the inner area of the Active Cells that
belong to the World Grouping and Zone that
the input World Cell belongs to.
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).
Note that if you are not sure whether the Active Grid Grouping is currently synced
to the World Grouping of the Zone the
World Cell is part of, you should place
the calling code in a try/catch statement and look for a InvalidOperationException.
When this exception is thrown, you can
disregard it and exit whatever code is trying to use the distance.
Name | Type | Description |
---|---|---|
worldCell | WorldCell |
The World Cell whose distance from the inner area you want. |
distanceCheckMethod | DistanceCheckMethod |
The method used to calculate the distance. |
int
The calculated distance.
If the Active Grid is synced to separate repeated/endless instances of the World Cell's
Zone, a distance value is computed for each, and
the smallest computed distance is returned.
Type | Condition |
---|---|
UninitializedSAMObjectException | Thrown if the method is called before the Active Grid is initialized. |
InvalidOperationException | Thrown if the method is called for an Active Grid Grouping that is not synced to a World Grouping. |
public LoadingBlueprint GetFallbackLoadingBlueprintOfGrouping(int activeGridGrouping)
Gets the Fallback Loading Blueprint associated with a specific World Grouping.
Name | Type | Description |
---|---|---|
activeGridGrouping | int |
The index of the Active Grid Grouping you are inquiring about, as shown in the Active Grid inspector. |
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 int GetGroupingIndexUsingGroupingName(string groupingName)
Gets the index of the Grouping indicated by groupingName.
Name | Type | Description |
---|---|---|
groupingName | string |
The name of the Grouping. |
int
The index of the grouping as it appears in the inspector, or -1 if no Grouping with
the groupingName exist on this Active Grid.
public void GetRegisteredActiveCells(int activeGridGrouping, ICollection<ZoneGroupingLODCell> cells, bool clearCollectionIfNotEmpty)
Fills the input cells collection with all currently registered active ZoneGroupingLODCells
associated with the input Active Grid Grouping.
These are the Cells the Grouping has registered itself as a user of with the World.
Note, if the Grouping is not currently synced to a World Grouping, or is not currently
updating the World with its
Active Cells, no cells will be added to the cells collection, but it will still be
cleared if clearCollectionIfNotEmpty is true.
Name | Type | Description |
---|---|---|
activeGridGrouping | int |
The index of the Active Grid Grouping you are inquiring about, as shown in the Active Grid inspector. |
cells | ICollection<ZoneGroupingLODCell> |
A container for storing the currently active cells. The container can be a lists, hashset, or any other collection that implements ICollection<ZoneGroupingLODCell> |
clearCollectionIfNotEmpty | bool |
Whether the cells collection should be cleared if it is not already empty, before adding the active cells. |
public bool HasCellsRegistered(int activeGridGrouping)
Gets a value indicating whether the Active Grid Grouping specified is currently synced
to a World Grouping and
has Active Cells registered with the World.
To have Active Cells registered with the World 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 |
---|---|---|
activeGridGrouping | int |
The index of the Active Grid Grouping you are inquiring about, as shown in the Active Grid inspector. |
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 activeGridGrouping)
Gets the value of Enable Auto Tracking (as shown in the inpsector) for an Active Grid
Grouping. This value
indicates whether the Player's position is being automatically tracked in
order to update the Active 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, and the Grouping must be synced to
a matching World Grouping on the World.
Name | Type | Description |
---|---|---|
activeGridGrouping | int |
The index of the Active Grid Grouping you are inquiring about, as shown in the Active Grid inspector. |
bool
True if auto tracking is enabled, false otherwise.
public bool IsGroupingSynced(int activeGridGrouping)
Gets a value indicating whether the Active Grid Grouping specified is currently synced
to a World Grouping.
This will be true if the Active Grid is synced to a World and that World contains
a World Grouping with
the same Grouping Name as the specified Active Grid Grouping.
Name | Type | Description |
---|---|---|
activeGridGrouping | int |
The index of the Active Grid Grouping you are inquiring about, as shown in the Active Grid inspector. |
bool
True if the Active Grid Grouping is synced to a World Grouping, false otherwise.
public bool IsUpdatingWorld(int activeGridGrouping)
Gets the value of Update World (as shown in the inspector) for an Active Grid Grouping.
Note that even if this value is true, it doesn't necessarily mean that
the Grouping will be updating the World on its Active Cells. For example, if the Grouping
could not be matched to a
World Grouping, it will be idle.
If you are trying to determine if the Grouping is actually synced to a World Grouping
and has Active Cells
currently registered with the World, use
HasCellsRegistered instead.
Name | Type | Description |
---|---|---|
activeGridGrouping | int |
The index of the Active Grid Grouping you are inquiring about, as shown in the Active Grid inspector. |
bool
True if the World is being updated about the active grid cells for the layer, false
otherwise.
public void PreInitialize_RemoveZoneBlueprintOverride(int groupingIndex, bool overwritePersistentDataSettings, string zoneName)
Attempts to remove a Zone Blueprint Override which has been added in the inspector or added via a call to one of the PreInitialize_SetLoadingBlueprint... methods (in which a zoneName was been passed in).
Name | Type | Description |
---|---|---|
groupingIndex | int |
The index of the Active Grid Grouping to change. |
overwritePersistentDataSettings | bool |
Whether the removal operation should override any persistent data settings that have or may be loaded. If you pass in true and a Zone Blueprint Override exist for the specified zoneName, that Blueprint will not be applied since the override technically no longer exist. Conversely, if you pass in false and a Zone Blueprint Override exists, that Blueprint will be applied and this removal operation will be "canceled out" so to speak. |
zoneName | string |
The name of the Zone whose override should be removed. |
Type | Condition |
---|---|
InitializedSAMObjectException | Thrown when this method is called after the Active Grid has been initialized. |
public void PreInitialize_SetLoadingBlueprintByID(int groupingIndex, int loadingBlueprintID, bool overwritePersistentDataSettings, string zoneName = null)
Changes either the Fallback Loading Blueprint used by the
Active Grid Grouping indicated (if zoneName is null), or the Loading Blueprint Override
for a specific Zone only (if zoneName is not null).
This allows 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.
If zoneName is not null, the Blueprint will only apply to the Zone specified. If a
Zone Blueprint Override already exists
(because it was added in the inspector), it will be updated
with the new Blueprint, otherwise a new runtime only override will be added.
If at some point you don't wish for this override to apply any longer, you must
remove it (after which, when synced to the specified Zone, the Fallback Loading Blueprint
for the Active Grid Grouping will be used).
If zoneName is null, the blueprint change is applied to the Fallback Loading Blueprint
for the Active Grid Grouping specified. This Grouping will
use that Blueprint when synced to any Zone that does not have a Zone Blueprint Override.
Changes made here will be saved when saving persistent data, unless overwriteLoadingBlueprintFromPersistentData
is false and you load
persistent data after calling this method.
Name | Type | Description |
---|---|---|
groupingIndex | int |
The index of the Active Grid 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. |
overwritePersistentDataSettings | bool |
When zoneName is null, determines whether the new loading blueprint you indicated
should overwrite the fallback loading blueprint
found in persistent data for this Active Grid Grouping (if any exist).
|
zoneName | [string] |
The name of the Zone to apply this blueprint to, or null if you want the blueprint to be applied to the Fallback Loading Blueprint for the Active Grid Grouping instead. |
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 overwritePersistentDataSettings, string zoneName = null)
Changes either the Fallback Loading Blueprint used by the
Active Grid Grouping indicated (if zoneName is null), or the Loading Blueprint Override
for a specific Zone only (if zoneName is not null).
This allows 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.
If zoneName is not null, the Blueprint will only apply to the Zone specified. If a
Zone Blueprint Override already exists
(because it was added in the inspector), it will be updated
with the new Blueprint, otherwise a new runtime only override will be added.
If at some point you don't wish for this override to apply any longer, you must
remove it (after which, when synced to the specified Zone, the Fallback Loading Blueprint
for the Active Grid Grouping will be used).
If zoneName is null, the blueprint change is applied to the Fallback Loading Blueprint
for the Active Grid Grouping specified. This Grouping will
use that Blueprint when synced to any Zone that does not have a Zone Blueprint Override.
Changes made here will be saved when saving persistent data, unless overwriteLoadingBlueprintFromPersistentData
is false and you load
persistent data after calling this method.
Name | Type | Description |
---|---|---|
groupingIndex | int |
The index of the Active Grid 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. |
overwritePersistentDataSettings | bool |
When zoneName is null, determines whether the new loading blueprint you indicated
should overwrite the fallback loading blueprint
found in persistent data for this Active Grid Grouping (if any exist).
|
zoneName | [string] |
The name of the Zone to apply this blueprint to, or null if you want the blueprint to be applied to the Fallback Loading Blueprint for the Active Grid Grouping instead. |
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 overwritePersistentDataSettings, string zoneName = null)
Changes either the Fallback Loading Blueprint used by the
Active Grid Grouping indicated (if zoneName is null), or the Loading Blueprint Override
for a specific Zone only (if zoneName is not null).
This allows 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.
If zoneName is not null, the Blueprint will only apply to the Zone specified. If a
Zone Blueprint Override already exists
(because it was added in the inspector), it will be updated
with the new Blueprint, otherwise a new runtime only override will be added.
If at some point you don't wish for this override to apply any longer, you must
remove it (after which, when synced to the specified Zone, the Fallback Loading Blueprint
for the Active Grid Grouping will be used).
If zoneName is null, the blueprint change is applied to the Fallback Loading Blueprint
for the Active Grid Grouping specified. This Grouping will
use that Blueprint when synced to any Zone that does not have a Zone Blueprint Override.
Changes made here will be saved when saving persistent data, unless overwriteLoadingBlueprintFromPersistentData
is false and you load
persistent data after calling this method.
Name | Type | Description |
---|---|---|
groupingIndex | int |
The index of the Active Grid 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. |
overwritePersistentDataSettings | bool |
When zoneName is null, determines whether the new loading blueprint you indicated
should overwrite the fallback loading blueprint
found in persistent data for this Active Grid Grouping (if any exist).
|
zoneName | [string] |
The name of the Zone to apply this blueprint to, or null if you want the blueprint to be applied to the Fallback Loading Blueprint for the Active Grid Grouping instead. |
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_SetStartingPlayerPosition(Vector3 startingPosition)
Allows you to set the Player's starting position. Note that if you are assigning the
player at runtime, you can simply change the player's position
before assigning it to the Active Grid using PreInitialize_SetPlayer. You can also
adjust the position of the Player in the editor when using a
Transform based player that is assigned to the Active Grid via its inspector.
This method is useful if you need to procedurally set the starting position of the
player at runtime and either don't have access to the Player used by
the Active Grid, or it has not been created yet.
Note that because this position is intended to serve as a starting position (i.e.,
a new game start position),
it will only be used in the following situations:
1) You do not use PreInitialize_SetPlayer before/after this method is called, and
either SAM persistent data is either not loaded,
the player position in that data is not valid, or Ignore Player Position In Persisten
Data is enabled.
2) You use PreInitialize_SetPlayer before/after this method is called and SAM persistent
data is not loaded. If you use PreInitialize_SetPlayer
and persistent data is loaded, then the starting position will never be used, as SAM
will assume the player's position should come from
either the persistent data (if it is valid and Ignore Player Position In Persisten
Data is disabled is disabled) or the existing position of
the Player that is passed into the PreInitialize_SetPlayer method.
Name | Type | Description |
---|---|---|
startingPosition | Vector3 |
The starting position to use for the Player. |
Type | Condition |
---|---|
InitializedSAMObjectException | Thrown when this method is called after the Active has been initialized. |
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, string zoneName = null)
Tries to change the Fallback Loading Blueprint (if zoneName is null)
of the indicated Active Grid Grouping, or it tries to change/add a Zone Blueprint
Override (if zoneName is not null).
The 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 refresh only occurs if an actual Blueprint
change is detected.
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 Active Grid 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. Only occurs if an actual Blueprint change is detected.
|
zoneName | [string] |
An optional Zone to apply the blueprint to. If null, the blueprint change will be
applied to the Fallback Loading Blueprint of the Active
Grid Grouping specified. If not null, the blueprint change will be applied to an existing
Zone Blueprint Override matching the zoneName, or a
new Override will be created if one does not already exist.
|
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, string zoneName = null)
Tries to change the Fallback Loading Blueprint (if zoneName is null)
of the indicated Active Grid Grouping, or it tries to change/add a Zone Blueprint
Override (if zoneName is not null).
The 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 refresh only occurs if an actual Blueprint
change is detected.
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 Active Grid 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. Only occurs if an actual Blueprint change is detected.
|
zoneName | [string] |
An optional Zone to apply the blueprint to. If null, the blueprint change will be
applied to the Fallback Loading Blueprint of the Active
Grid Grouping specified. If not null, the blueprint change will be applied to an existing
Zone Blueprint Override matching the zoneName, or a
new Override will be created if one does not already exist.
|
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, string zoneName = null)
Tries to change the Fallback Loading Blueprint (if zoneName is null)
of the indicated Active Grid Grouping, or it tries to change/add a Zone Blueprint
Override (if zoneName is not null).
The 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 refresh only occurs if an actual Blueprint
change is detected.
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 Active Grid 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. Only occurs if an actual Blueprint change is detected.
|
zoneName | [string] |
An optional Zone to apply the blueprint to. If null, the blueprint change will be
applied to the Fallback Loading Blueprint of the Active
Grid Grouping specified. If not null, the blueprint change will be applied to an existing
Zone Blueprint Override matching the zoneName, or a
new Override will be created if one does not already exist.
|
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 indicated Active Grid Groupings
(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 blueprints (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 |
---|---|---|
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 Active Grid 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.
|
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 indicated Active Grid Groupings
(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 blueprints (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 |
---|---|---|
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 Active Grid 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.
|
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 indicated Active Grid Groupings
(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 blueprints (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 |
---|---|---|
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 Active Grid 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.
|
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 IEnumerator<YieldInstruction> TryRemoveZoneBlueprintOverride(int groupingIndex, string zoneName, bool refreshWorld)
Tries to remove a Zone Blueprint Override for the zoneName on the indicated Active
Grid 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 |
---|---|---|
groupingIndex | int |
The Active Grid Grouping whose Zone Blueprint Override will be removed. |
zoneName | string |
The name of the Zone to remove the override for. If an override for this Zone does not exists, nothing will happen and the method will return with a SimpleYieldBreakEquivalentEnumerator object. |
refreshWorld | bool |
If true and the removal of the override results in a change of Blueprint, and thus
a change in cells loaded for the Zone in question,
the World will be updated with the changed cells.
|
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 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 Grid Grouping that
has a matching Grouping on the World.
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 Grid 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
Grid 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 Groupings that cannot be matched
to the World. In this case, all groupings
on the Active Grouping are updated, even if a Grouping does not have a matching Grouping
on the World. In this way, if the
Active Grid becomes synced to a World that does have a 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 Grid 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 Grid 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
Grid 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 Grid Grouping that
has a matching Grouping on the World.
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
each Active Grid Grouping is updated dynamically as a result of the player moving
across the current inner area boundary of
that 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
Grid Grouping,
as well as the dimensions of the cells on the matching World Grouping for each Active
Grid Grouping.
This method is the same as
TrySetIfWorldShouldBeUpdated,
except that this 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 Grid 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 Grid 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
Grid 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. |