This document is about: QUANTUM 2

This page is a work in progress and could be pending updates.

Extending Assets for Unity


Quantum assets can be extended with Unity-specific data not relevant for the simulation like data for the UI (colors, texts, icons...). This is done with the use of partial classes.


Let's take the CharacterSpec asset as an example. Its ScriptableObject-based wrapper in Unity is called CharacterSpecAsset and is the type which needs to extended.


public partial class CharacterSpecAsset {
  public Sprtie Icon;
  public Color Color;
  public string DisplayName;
These fields can only be accessed in the View (Unity) and cannot be accessed or used in the simulation (Quantum).

The newly created partial class needs to be added to the same assembly as the original definition of CharacterSpecAsset. By default, all Unity-side Quantum code belongs to the PhotonQuantum assembly.

To ensure the partial class belongs to the correct assembly use one of the following approaches:

  • Save the class in Assets/Photon/Quantum/User directory.
  • Save the class in any directory that has an AssemblyDefinitionReference asset pointing to the PhotonQuantum assembly.
  • Delete Assets/Photon/Quantum/PhotonQuantum.asmdef. This will make Quantum a part of the main assembly. Note that this step needs to be repeated after each Quantum SDK update.

Access at Runtime

To access the extra fields at runtime, use the UnityDB.FindAsset<T>() method.


CharacterSpecAsset characterSpecAsset = UnityDB.FindAsset<CharacterSpecAsset>(guid);

Alternatively, the code-generated GetUnityAsset() extension methods can be used:


CharacterSpec characterSpec = frame.FindAsset<CharacterSpec>(guid);
CharacterSpecAsset characterSpecAsset = characterSpec.GetUnityAsset();

Both of the approaches will result in the asset being loaded into Quantum's AssetDB using the appropriate method, as discussed here: Resources, Addressables and Asset Bundles.

Access at Edit-time

To load an asset using its path while in the Unity Editor, the UnityEditor.AssetDataBase.LoadAssetAtPath<T>() method can be used.


CharacterSpecAsset characterSpecAsset = UnityEditor.AssetDatabase.LoadAssetAtPath<CharacterSpecAsset>(path);

Alternatively, the asset can be loaded using its AssetGuid via the UnityDB.FindAssetForInspector() method and casting the result to the correct type.


CharacterSpecAsset characterSpecAsset = (CharacterSpecAsset)UnityDB.FindAssetForInspector(guid);
Back to top