Subscribed Items

Like what your seeing?

Support us as a GitHub Sponsor and get instant access to all our assets, exclusive tools and assets, escalated support and issue tracking and our gratitude. These articles are made possible by our GitHub Sponsors ... become a sponsor today!

Introduction

Workshop lets your users create and upload items and then subscribe to other user's items to extend and enhance there game. This article will go over the tools available for detecting what items the user is "subscribed" to and how to find more information about those items such as where they are installed so you can load their content.

Finding the subscribed items

The simplest approach to find what items the user is subscribed to is to use the UGCQuery tool and search for all subscribed items.

var query = UgcQuery.GetSubscriobed();

This will give you a UgcQuery object configured to return the list of items the local user is subscribed to. You can further adapt this query to suit your own needs. For example if your game's items use metadata then you should set the query to also return metadata.

query.SetReturnMetadata(true);

Once your query is configured as required you can simply execute the query and iterate over its results.

query.Execute(callback);

results will be a reference to the same UgcQuery this allows you to use a pre-defined method such as

query.Execute(HandleQueryResults);

where

void HandleQueryResults(UgcQuery results)
{
    //Do Work
}

Or you can use expression to create an anonymous method to handle the results such as

query.Execute(results =>
{
    //Do Work
});

These are functionally the same.

Using the results

Once you have executed your query and have a list of results you need to use those results to do what your game needs. Typically this would be to load the content stored on the item and possibly to read its metadata.

void HandleQueryResults(UgcQuery results)
{
    foreach(item in results.ResultsList)
    {
        //The FolderPath is the DirectoryInfo of the folder 
        //the item content is located in
        Debug.Log("Content present in " + item.FolderPath.FullName);
        
        //The metadata string is the metadata found if any 
        Debug.Log("Content metadata: " + item.metadata);
    }
}

Last updated