Give Page Feedback | API

Players - Overview

In SAM - The Streamable Assets Manager, Players are sipmly entities with position which are tracked by Active Grids in order to drive dynamic updates of the World.

A Player does not necessarily need to be controllable by the humans playing your game, though in most cases they will be.

The IPlayer Interface

Any class that implements the IPlayer interface can be considered a Player in SAM. This interface is very minimalistic, containing a single Position property. This property uses the Vector3Double type, which is basically a double type version of Vector3. There is an implicit conversion available from Vector3 to Vector3Double, however in order to do the reverse you must explicitly convert the Vector3Double to a Vector3 by casting it to a Vector3.

This interface introduces a flexible system where you can pretty much make any existing class into a Player object that the Active Grid recognizes and can interact with.

--Transform Players--
Because Transforms are likely to be the most common form of Player objects, Active Grids are able to use them directly as Players, either via the inspector or via scripting. Under the hood, a special TransformPlayer object is created that implements the IPlayer interface so that you do not have to go through the trouble of doing so yourself. You can just use the Transform directly and all the other work is taken care of for you.

--Custom Players--
The CustomPlayer class is a special abstract class that derives from MonoBeheviour. If you want a specific component (that isn't a Transform component)to serve as the Player, you can set that component to derive from CustomPlayer rather than MonoBehaviour. You still need to implement the Position property yourself, but deriving from this class will allow you to assign the Player directly to the Active Grid in the inspector (although you can also assign it via scripting if you wish).

--Non Component Players--
Players do not need to be Components/MonoBehaviors. You can use normal C# classes as Players by simply having those classes implement the IPlayer interface. In order to assign them to Active Grids, however, you will need to use scripting.

Assigning Players Via Scripting

If using a non Component Player object, or a Transform or Component Player object that is only created at runtime (and thus not assignable in the Editor), you can assign it to an Active Grid using the PreInitialize_SetPlayer method.

You may pass in a Transform component or IPlayer object as the Player, as well as a PlayerMover object (see Player Movers Chapter for more information on Player Movers).

As the name implies, this method must be called before the Active Grid has been initialized, which means before the Component Manager has been initialized. Once initialized, the Player is locked in and cannot be changed.

The method has two additional parameters, overrideIgnorePlayerPositionInPersistentData and ignorePlayerPositionInPersistentData:

By default, Ignore Player Position In Persistent Data is a setting you can configure via the Active Grid's inspector. If you want to override that setting to use a different value for the Player you are assigning, set overrideIgnorePlayerPositionInPersistentData to true. If you pass in false, the ignorePlayerPositionInPersistentData value you pass in is ignored.

Set ignorePlayerPositionInPersistentData to true if you want positional data in the persistent data that the Component Manager saves to be ignored. This is useful if you are saving the position data yourself and want to set it yourself.

Positioning Players In The Scene

When using Streamable Assets, it can be difficult to figure out where the Player should be placed. Fortunately, the World Designer Tool is a great resource for rectifying this problem.

You can open this tool via the World component. When you do, set the Origin Cell for the Tool to the same Origin Cell you plan on starting your game using. Don't worry about the Origin Position, as this is automatically set to the same Origin Position used by the World.

After loading the Streamable Grid Cells in the area where you think you might like to place the Player, you can position the Player. Remember these two things, however:

1) The Player's Position is only used if no persistent data exists. If such data does exist, the position set in the scene will be overwritten by the position in the persistent data.

2 If you are using Terrain and the Terrain is serving as your ground, and you want the Player to start standing on that Terrain, it can be easier to let the Active Grid automatically set the Player's Y Position.

The Active Grid will automatically find the Terrain height that corresponds to the Players x and z position, then set the y position of the player to that height (plus an offset value, which you can specify if needed in the Active Grid inspector).