Give Page Feedback | API

Player Movers - How To Create Custom Player Movers

The Player Mover is an optional component which can be used to move an IPlayer object when it needs to be moved, such as during a Origin Cell Change. It allows you to fully control the movement behavior, including when during the Unity Frame Lifecycle the move occurs.

To start, create a new MonoBehaviour script that derives from the PlayerMover base abstract class.

You should place your class inside of the DeepSpaceLabs.SAM namespace, which will make the PlayerMover class available and also help avoid naming conflicts with 3rd party assets or your own code.

--Special Note--
An easy way to start with your custom class is to hover over your custom class name and choose the option Show potential fixes -> Implement abstract class. This will provide default overrides for all abstract class members.

In addition, we recommend adding the following attribute above your class, which will ensure the custom player mover is shown with other Player Movers in menus:

[AddComponentMenu(GlobalValues.COMPONENT_ROOT_PATH + "Player Movers/Custom Player Mover Name")]

MovePlayerByAmount (Method - Implementation Required)

When overridden, should move the player specified by the Vector3Double amount. That is, the amountToMovePlayer should be added to the existing player's position by the time the method finishes executing.

MovePlayerToPosition (Method - Implementation Required)

When override, should move the player specified to the specified position in world space by the time the method finishes executing.

Immediate Mode

Immediate mode is a special mode intended to force the Player Mover to execute its logic all at once. Currently it is only used with World Shifter's whose 'Perform Shift In Single Frame' setting is enabled, and only with the MovePlayerByAmount method, however in the future it could be used in more instances and with the MovePlayerToPosition.

In some instances, it may not be possible to use immediate mode, as your Player Mover may require the use of yield statements to execute different code at different points in the frame cycle, or in different frames altogether. At the moment, if this applies to your Player Mover(s), you must forego the use of the 'Perform Shift In Single Frame' setting (by disabling it) on any World Shifters you are using.