---
updatedAt: 2025-11-11T16:21:36.000Z
agentTools:
  projectIndex: https://beamable2.readme.io/llms.txt
---

# Content - Code

Create and manage your game's live content [PROF-Content-03]

<ul class="breadcrumb">
  <li><a href="/docs/">Docs</a></li>
  <li><a href="/docs/profile-storage">Profile & Storage</a></li>
  <li><a href="/docs/content-feature-overview">Content</a></li>
  <li>Content - Code</li>
</ul>

<div class="links">
  <a class="link normal" href="/docs/content-feature-overview" style={{textDecoration: 'none'}}>Overview</a>
  <a class="link normal" href="/docs/content-guide" style={{textDecoration: 'none'}}>Guide</a>
  <a class="link active" href="/docs/content-code" style={{textDecoration: 'none'}}>Code</a>
  <a class="link normal" href="/docs/content-custom-content" style={{textDecoration: 'none'}}>Custom Content</a>
  <a class="link normal" href="/docs/content-remote-configuration" style={{textDecoration: 'none'}}>Remote Configuration</a>
  <a class="link normal" href="/docs/content-validation" style={{textDecoration: 'none'}}>Validation</a>
  <a class="link normal" href="/docs/content-manager-overview" target="_blank" style={{textDecoration: 'none'}}>Tool Window</a>
</div>

## Code

> 📘 Beamable SDK Examples
>
> • The following example code is available for download at <a target="_blank" href="https://www.Github.com/beamable/Beamable_SDK_Examples/">GitHub.com/Beamable\_SDK\_Examples</a>

Here are API highlights for <a target="_blank" href="https://csharp.cdocs.beamable.com/latest/classBeamable_1_1Content_1_1ContentService.html#details">ContentService</a>.

### Subscribe

```csharp
private async void SetupBeamable()
{ 
    var beamContext = BeamContext.Default;
    await beamContext.OnReady;
      
    // Fetch All  
    beamContext.Api.ContentService.Subscribe(clientManifest =>
    {
        Debug.Log($"#1. ContentService, all object count = {clientManifest.entries.Count}");
    });

    // Fetch Filtered 
    beamContext.Api.ContentService.Subscribe("items", clientManifest =>
    {
        Debug.Log($"#2. ContentService, filtered 'items' object count = {clientManifest.entries.Count}");
    });
}
```

### Content Subscription vs ContentLink/ContentRef

Beamable supports subscriptions to Content as well as direct references to certain pieces of content. Both of these will allow you to download content from the server, depending on the Game Maker's needs.

Subscriptions use a PlatformSubscription to dynamically read the data on the server, and fire a callback when the data is changed. However, ContentLink and ContentRef are both resolved manually when the data is needed:

```csharp ContentServiceExistingExample.cs
using System;
using Beamable.Common.Content;
using Beamable.Common.Inventory;
using UnityEngine;

namespace Beamable.Examples.Services.ContentService
{
    [Serializable]
    public class ItemLink : ContentLink<ItemContent> {}
    
    /// <summary>
    /// Demonstrates <see cref="ContentService"/>.
    /// </summary>
    public class ContentServiceExistingExample : MonoBehaviour
    {
        //  Fields  ---------------------------------------
        [SerializeField] private ItemLink _itemLink;
        [SerializeField] private ItemRef _itemRef;

        private ItemContent _itemContentFromLink = null;
        private ItemContent _itemContentFromRef = null;
        
        //  Unity Methods  --------------------------------
        protected void Start()
        {
            Debug.Log($"Start()");
            
            SetupBeamable();
        }

        //  Methods  --------------------------------------
        private async void SetupBeamable()
        {
            var beamContext = BeamContext.Default;
            await beamContext.OnReady;
      
            Debug.Log($"beamContext.PlayerId = {beamContext.PlayerId}");
            
            await _itemLink.Resolve()
                .Then(content =>
                {
                    _itemContentFromLink = content; 
                    Debug.Log($"_itemContentFromLink.Resolve() Success! " +
                              $"Id = {_itemContentFromLink.Id}");
                })
                .Error(ex =>
                {
                    Debug.LogError($"_itemContentFromLink.Resolve() Error!"); 
                });
            
            await _itemRef.Resolve()
                .Then(content =>
                {
                    _itemContentFromRef = content; 
                    Debug.Log($"_itemContentFromRef.Resolve() Success! " +
                              $"Id = {_itemContentFromRef.Id}");
                    
                }).Error(ex =>
                {
                    Debug.LogError($"_itemContentFromRef.Resolve() Error!"); 
                });
        }
    }
}
```

> 📘 Best Practice
>
> These hints make efficent use of concepts and workflows.
>
> If the content that your game is using is known ahead of time (e.g. there will only be subtle differences in existing pieces of content), a content reference (such as ContentLink or ContentRef) should be used.
>
> However, if the content in your game needs to be more dynamic (e.g. the Game Maker will be pushing entirely new pieces of content, unknown to the game client), a content subscription should be used.

### GetContent Method

Beamable's ContentService has another method that can pull content: GetContent. Since this method will attempt to pull several pieces of content at once, it is often inefficient, however it may be useful depending on the scope of your project.

```csharp
private string contentIdToLoad;

private async void GetContent()
{
    var rawContent = await _beamContext.Api.ContentService.GetContent(contentIdToLoad); //Returns as IContentObject
    var content = rawContent as ItemContent;
    //content can now be used as ItemContent
}
```

## Advanced

This section contains any advanced configuration options and workflows.

<HTMLBlock>{`
<style>
  .iconImg
  {
    max-width: 32px;
    max-height:32px;
    margin: -20px -5px -10px -10px !important;
  }
</style>
`}</HTMLBlock>

### ContentLink vs ContentRef

Beamable supports 2 methodologies for referencing a content object; <a href="https://csharp.cdocs.beamable.com/latest/classBeamable_1_1Common_1_1Content_1_1ContentLink.html" target="_blank">`ContentLink`</a> and <a href="https://csharp.cdocs.beamable.com/latest/classBeamable_1_1Common_1_1Content_1_1ContentRef.html" target="_blank">`ContentRef`</a>. While they are both very similar syntactically and need to be resolved before using, they perform differently and have different use-cases.

* `ContentLink` - Beamable will perform a <Glossary>First Frame</Glossary> load to resolve the reference. `ContentLink`s must be present and resolvable (that is, they cannot be `null`)
* `ContentRef` - Beamable will perform a <Glossary>Lazy</Glossary> load to resolve the reference. As such, it is okay for a `ContentRef` to be `null` as long as it is never resolved

See [Content » Guide (Steps)](https://beamable2.readme.io/docs/content-guide#step) for more info.

> 📘 Best Practice
>
> These hints make efficent use of concepts and workflows.
>
> * DO: Use `ContentLink` in any member variable in your *custom* content type which references another content type. ContentLink is useful for data that needs to be loaded quickly at runtime, since it is preloaded in very early stages of the application's lifecycle.
> * DON'T: Use `ContentRef` by default *everywhere* in your project. This is supported but is considered overkill. ContentRef is useful for data that the application can afford to load on-demand (especially data that might not get loaded at all).

### Content Caching

Content is cached by the client and stored both in memory and persisted to disk. When content is updated on our backend, Beamable updates a client manifest and push it to all clients to invalidate and update the cache.

See source code of `Runtime/DisruptorEngine/Content/ContentCache.cs` for more info.

### Content ID

The content ID is assigned at creation, and is composed of content `type` and content `id`. A content ID always starts with the content type.

For example, a currency content for dollars would be `currency.dollars`.

**Nesting**

Content may be nested too, and the resulting hierarchy will be baked in to the name.

For example, to group "weekend" events under a common folder -- the content ID would be `events.weekend.<user-defined-id>`.

### Content Serialization

Unity's built-in features use [Unity's serialization](https://docs.unity3d.com/Manual/script-Serialization.html).

However, Beamable's custom content types rely instead on Beamable's custom <Glossary>Serialization</Glossary>. This serialization is strict and has limitations.

<Table align={["left","left"]}>
  <thead>
    <tr>
      <th>
        Supported Types
      </th>

      <th>
        Unsupported Types
      </th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>
        •	Unity’s <a href="https://docs.unity3d.com/Packages/com.unity.addressables@0.3/api/UnityEngine.AddressableAssets.AssetReference.html" target="_blank">`AssetReference`</a>
        •	Unity’s <a href="https://docs.unity3d.com/ScriptReference/Color.html" target="_blank">`Color `</a>
        •	`bool`
        •	`double`
        •	`enum`
        •	`float`
        •	`int`
        •	`List`
        •	`long`
        •	`string`
        •	`System.Object` (and child types)
        •	<a href="https://csharp.cdocs.beamable.com/latest/classBeamable_1_1Common_1_1Content_1_1ContentRef.html" target="_blank">`ContentRef `</a>
        •	<a href="https://csharp.cdocs.beamable.com/latest/classBeamable_1_1Common_1_1Content_1_1ContentLink.html" target="_blank">`ContentLink`</a>
      </td>

      <td>
        •	Unity’s <a href="https://docs.unity3d.com/ScriptReference/MonoBehaviour.html" target="_blank">`MonoBehaviour`</a>  
        •	Unity’s <a href="https://docs.unity3d.com/ScriptReference/ScriptableObject.html" target="_blank">`ScriptableObject`</a>  
        •	Etc...
      </td>
    </tr>
  </tbody>
</Table>

**Excluding Fields from Serialization**

The `[IgnoreContentFieldAttribute]` can be applied to any field that you wish to exclude from the Content Serialization process.

```csharp MyCustomContent.cs
[Agnostic]
[ContentType("MyCustomContent")]
public class MyCustomContent : ContentObject 
{
     public string Name;
     public AssetReferenceSprite Icon;

     [IgnoreContentFieldAttribute]
     public Dictionary<string, int> KeyValuePair;

}
```

### Content Validation

Beamable supports optional validation for each field of a `ContentObject` subclass. This allows game makers to easily build tooling to facilitate team members with their content administration tasks.

See [Content - Validation](https://beamable2.readme.io/docs/content-validation) for more info.

### Storage Location of Content Types

Each content object derives from Unity's <a href="https://docs.unity3d.com/Manual/class-ScriptableObject.html" target="_blank">`ScriptableObject`</a>, is an asset file written to disk, and is therefore persistent between sessions.

While all content objects must go in this location, game makers may choose to create custom subfolders within.

**Development (Unity Editor)**

```csharp
/Assets/Beamable/Editor/content/
```

**Deployment (On-device)**\
The development location is not included in the built game project. Instead, when the player loads the game, a fresh copy of all content is retrieved from the Beamable back-end and stored on-device. This allows Beamable to serve *dynamic* content to the game project. By default, this is a <Glossary>Lazy</Glossary> loading operation. Each of Beamable's <Glossary>Feature</Glossary> prefabs show a loading progress indicator UI automatically.

Content is stored on-device in a within Unity's <a href="https://docs.unity3d.com/ScriptReference/Application-persistentDataPath.html" target="_blank">`Application.persistentDataPath`</a>.

```csharp
 Application.persistentDataPath + $"/content/{contentId}.json";
```

### Game Content Designer

Config data, or “Content” as it is called within Beamable, is realm-scoped and can be deployed from either...

* **Unity** -  Via Unity's <a href="https://docs.unity3d.com/Manual/class-ScriptableObject.html" target="_blank">`ScriptableObject`</a>
* **Google Sheets** -  Via Beamable's [Game Content Designer](https://beamable2.readme.io/docs/game-content-designer)

Within the context of a CI/CD pipeline, game makers can create jobs that invoke the Content deployment function against data it pulled from source control, and pass in arguments for which realm this Content should go to. This is not theoretical, this is what game makers do today in production.

### Content with Microservices

This 'MyCustomContent.cs' snippet includes the  `[Agnostic]` attribute. To make content classes available to your microservices, add the attribute to your content classes.

See [Microservices](https://beamable2.readme.io/docs/microservices-feature-overview) for more info.

```csharp MyCustomContent.cs
[Agnostic]
[ContentType("MyCustomContent")]
public class MyCustomContent : ContentObject { ... }
```

### Content Namespaces

> 🚧 Global Namespace
>
> Beamable APIs that use content under the hood can *only* look to the global namespace.

```csharp
public class Tester : MonoBehaviour
{
    public CurrencyRef currency;

    async void Start()
    {
        var ctx = BeamContext.Default;

        ctx.Content.GetContent(content.Id, "tuna");

        var service = (ContentService)ctx.Content;
        service.SwitchDefaultManifestID("tuna");
        var content = await currency.Resolve();
    }
}
```

<HTMLBlock>{`
<style>
  .links {
    padding: 0 1em 1em 0;
    display: flex;
    flex-flow: row wrap;
  }

  .link {
    margin-right: 2em;
    margin-bottom: 0.75em;
    padding: 0.3em 1.5em;
    box-sizing: border-box;
  }

  .active {
    border: 1px solid #4274f6;
    background-color: #4274f6;
    color: white;
  }

  .normal {
    background-color: white;
    border: 1px solid gray;
    cursor:pointer;
  {{textDecoration: 'none'}}
  }

  .normal:active {
    background-color: #c4d4ff;
  }

  .normal:hover {
    background-color: #c4d4ff;
  }

  .active:active {
    color: white;
  }

  .active:hover {
    color: white;
  }
  
  ul.breadcrumb {
    padding: 10px 16px;
    list-style: none;
  }
  ul.breadcrumb li {
    display: inline;
    font-size: 18px;
  }
  ul.breadcrumb li+li:before {
    padding: 8px;
    color: black;
    content: "/\\00a0";
  }
  ul.breadcrumb li a {
    color: #0275d8;
    text-decoration: none;
  }
  ul.breadcrumb li a:hover {
    color: #01447e;
    text-decoration: underline;
  }
  
     @media only screen and (max-width:700px){
 		    ul.breadcrumb {
    padding-top:0;
          padding-left:0;
  }
      
       .link {
    margin-right: 1em;
         margin-bottom:1em;
  }
  }
</style>
`}</HTMLBlock>