Astra Unity 2.6.6
Astra Unity Plugin
All Classes Namespaces Functions Variables Enumerations Enumerator Properties Events Pages
Editor and Build Notes

This document has information about items that you will want to know in regards to making builds with Astra or using it in the Editor.

Initializing Astra for Builds

Astra needs to be initialized in order to perform queries, load assets, or run jobs. This boot process is handled through Astra.Configuration.Initialize (or it's related helper methods). This is an asynchronous request and as such it returns itself a job that you must wait upon before further action should take place. In addition to this there is an expected GameObject and Component that needs to be in your scene AstraManagerGO and Astra.AstraManager. You can easily add this via the Astra/Pres Scene menu option. Work that is requested will be added to a queue and will be run once initialized from the queue. It is important to remember that because of this behaviour you should always wait for Astra to be initialized before you perform work. This might mean that you poll Astra.AstraManager.IsReady or in a coroutine you call something like this:

using System.Collections;
using UnityEngine;
public class AstraBootExample : MonoBehaviour
{
// This should point to a JSON Astra Config file (dragged into this component)
public TextAsset myConfig;
void Start()
{
StartCoroutine(Boot());
}
IEnumerator Boot()
{
// Block waiting for Astra to self start
yield return Astra.AstraManager.WaitForInit();
// Block waiting for Astra to setup it's configuration
yield return Astra.Configuration.Initialize(myConfig).AsCoroutine();
UnityEngine.Debug.Log("Astra is ready");
// ... call your code now ...
}
}
IEnumerator AsCoroutine(Action< float > progress=null, Action< T1 > onComplete=null, Action< T2 > onFailed=null)
Wraps a job to be used within a coroutine
Definition: ApiJob.cs:69
AstraManager is a scene object which manages the Astra system. It must be initialized before other As...
Definition: AstraManager.cs:25
static AstraManager StartupAstra()
Used to initialize the Astra system. Creates an AstraManager scene object named "AstraManagerGO" if i...
Definition: AstraManager.cs:61
static IEnumerable WaitForInit()
Coroutine to wait for the Astra system to be initialized. It will check once per frame until it's rea...
Definition: AstraManager.cs:425
Allows you to initialize and configure the Astra library using JSON, Astra.ProjectConfiguration,...
Definition: Configuration.cs:67
static ProjectConfigJob Initialize(UnityEngine.TextAsset asset)
Triggers Initialize interally converting your text asset into json and parsing it
Definition: Configuration.cs:173
Definition: AnimationManager.cs:10

We recommend you do this in a bootup sequence for your application or game before entering into the rest of your code to keep things simpler, otherwise you will have lots of checks to see if Astra is ready to run sprinkled throughout all your MonoBehaviours.

Failure to initialize Astra or have it in the scene may cause issues with running Astra especially failures of launch of builds vs using Astra in the Editor environment.

Note: Astra does not persist your configuration data for you, you must determine the best way to initialize the configuration system yourself for your builds.

Editor, Edit vs Play, and Build differences

In the Unity Editor, there are many helper ways of initializing Astra so that you can use it without having to write a piece of code that boots it up. This can be done by clicking on the Init button on a JSON configuration file, for example. When triggering this in the Editor a component and GameObject will automatically be added to your scene as AstraManagerGO with Astra.AstraManager behaviour attached. This does not automatically occur in a build, but will occur in Editor in play mode. This is so that you can control the boot sequence in your program.

Difference Between Edit vs Play Mode

Astra performs a few tricks to get avatars to be loaded in Edit mode in Unity. We strive to ensure a What You See Is What You Get, WYSIWYG, so that you can easily work, dress, edit your characters in realtime in your scene. Since Astra is a procedural and streaming solution assets there are some quirks that come with this.

  1. When saving a scene the AvatarItem will automatically be serialized to the scene file including procedural textures.
    We have introduced experimental support for swapping out Texture2D elements right before save and right after load of scenes, this can be toggled in your Astra configuration file. This greatly reduces the time to save/load and file size, but does mean your textures will briefly pop off then re-load upon start.
  2. Occasionally you will need to enter play mode at least once on boot of Unity in order for blendshapes to work correctly.
  3. Some Astra configuration state persists between edit and play mode, especially if triggered in edit mode.
    This is for convenience, it's important that you understand the boot sequence as described above.

Differences Between Editor and Builds

There are no real differences between the Editor and Builds for Astra with the exception of configuration state persistance in the Editor. As stated before, you are responsible for booting and feeding Astra a configuration so it can start properly.

Offline Support and Local Database.

Astra currently requires an active network connection during initialization as it communicates back to servers. Work is being done to allow full offline support. Currently assets are installed into your local database and these will not be refetched unless updated on the server. This does allow you to pre-ship a database of assets if desired with your build.