Getting Started - Actors
There are two types of actors: RMB and Lambda.
RMB Actor
RMB actor comprises of Mothership and Satellite, which runs inside a session that BigScreen creates. This type of actor use TCP to support long running connection and streaming of data.
Lambda Actor
Lambda actor serves as cloud functions. These are HTTP web request that are meant to return response quickly and can auto scale to meet the demand by launching more lambda instance. This type of actor can be invoke at anytime, even outside of a session.
Because this actor runs on AWS Lambda, there is a hard limit of 30 second timeout. Ensure that your lambda actor return a response in a timely manner.
Cold Start
Cold Start is the term for handling a request by launching a lambda instance. Cold Start is slow because of additional time to startup the instance. It can take about ~1.5 seconds to complete a response.
When a lambda instance is idle for about 3 minutes, the instance is shutdown to scale down the service.
Warm Start
Warm Start is the term for handling a request using an already running lambda instance. Warm Start is fast and can complete a response under 0.5 seconds.
Persistent Storage
Lambda actor cannot hold any state. Do not store any data in the heap memory. Store the data in a persistent storage such as Entity Manager.
Once the lambda instance serves a request, the next request will reuse the same instance. Any data in heap memory can contaminate the next request.
When lambda instance goes down, data in heap memory is gone, and the next request would not have access to data in heap memory anymore.
Installation
The actor project utilize the Dedicated Server build target that's available from Unity 2021.3. This allows developer to create a linux console application that can run on AWS.
- Minimum Unity requirement is 2021.3
- From UnityHub, add module: Linux Dedicated Server Build Support
- Install the linux tool chain for your development platform, either:
-- Toolchain Linux x64 or
-- Toolchain MacOS Linux x64
-- Toolchain can be automatically install by going to Project Settings/Toolchain Management, toggle the checkbox
Install toolchain package automatically
.
There are a few restrictions to using this features:
- The toolchain only support x64, it cannot be install on arm64 mac. This means that actor project can only be built on
Intel mac
,Windows
, orLinux
desktop. - Dedicated Server is a relatively new feature from Unity that was release in late 2022. As such, it does not strip out all unused assets. Keep your actor project small to avoid long start up time. A minimum linux build is about 100MB.
Scripting Backend
must useIL2CPP
due to various dependency in the SDKCompatibility Level
must be.net standard 2.1
Managed Stripping Level
must beMinimum
. We find that even with various use ofpreserve
keyword andlink.xml
, Unity still strip out code if the level is aboveMinimum
ActorConfig
ActorConfig asset contains configuration for the actor.
Unlike BigScreen and Client, the ActorConfig is only used by Debugger. When actor runs in the cloud, its configuration comes from the BigScreen that sends to LobbyService.
Only one config file is required per project (shared by mothership/satellite/lambda). It can be created by right-click in Project panel Create/STREAMSIX/ActorConfig.
BaseMothership / BaseSatellite / BaseLambda
Extends the above base MonoBehaviour class for your mothership, satellite, and lambda app.
These are the main class that contains all the STREAMSIX features. You can use this to send/receive message from RMB, and access to other features in the paltform such as inventory and leaderboard.
Three separate scenes
Because mothership/satellite/lambda are separate application but sharing one Unity project, they are separated into their own scene.
Add the corresponding base class MonoBehaviour to each scene. No other component is needed to run the actor.
The Debugger can be use to build the actor from each of the scene into separate applications.
Debugger
Refer to Getting Started on setting up Actor project for the first time, which covers logging into Dev Portal and downloading RMB.
Run Actor In Local
In the Hierarchy, add Mothership, Satellite, Lambda scenes.
When entering PlayMode, Debugger spawns two RMB (mothership and satellite) which the actor will connect to. After which the BigScreen can connect to the actor.
Debugger also starts up a web server for invoking functions in lambda actor. The server listens at http://< RMB IP Address >:< Lambda SebServer Port >/
Ensure these values match the values in BigScreen's Debugger.
Build Actor
Debugger can be used to build actor.
Assign the three scenes to each of the fields in Build Actor
section. After which the Build Now
button will become available.
Click on Build Now
button will trigger build process. Debugger creates three Unity builds, one for each scene. (This is because mothership/satellite/lambda are all separate applications).
Mothership and satellite builds are zip into build/unity_rmb_actor.zip
Lambda builds is zip into build/unity_lambda_actor.zip
Once build is complete, the RMB Actor
and Lambda Actor
fields are enabled to indicate the builds are available.
Upload to Dev Portal
First, login to Dev Portal.
If a build exist from the previous section, the Upload Now
button will be available. Supply a description to upload the build.
Once upload is complete, the depot list will refresh and the new upload will appear in the list with an auto-generated ID. This ID is always incrementing so the highest number is the most recent upload.
For BigScreen to use the uploaded actor, refer to Managing Unity Actor on how to assign the build to a branch on Dev Portal. This step can only be done on Dev Portal website.