⚡Quickstart - Unity SDK

Get started with the Unity SDK in under 10 minutes.

If you followed the Set-up Unity & Import the SDK section, your script should look something like this:

[SerializeField] private Animator myAnimator;
[SerializeField] private string myConnectedUserID;

private void Awake() 
{
	KinetixCore.OnInitialized           += OnInitialize;
	KinetixCore.Initialize(new KinetixCoreConfiguration()
	{
		GameAPIKey = "yourGameAPIKey",
		PlayAutomaticallyAnimationOnAnimators = true,
		EnableAnalytics = true
	});
}

// This callback is used for the actions made after the SDK is initialized
// Such as initializing the UI and Registering our LocalPlayer's animator
private void OnInitialize()
{
	// Register local player to receive animation
	// See "Animation System" documentation
	KinetixCore.Animation.RegisterLocalPlayerAnimator(myAnimator);

	// Now, we connect the current user's account to get his emotes
	// The userID is chosen by you, and must be unique to each user
	// See "Account Management" documentation
	KinetixCore.Account.ConnectAccount(myConnectedUserID, () => {
		Debug.Log("Account connected successfully");
	}, () => {
		Debug.LogError("There was a problem during account connection. Is the GameAPIKey correct?");
	});
}

Next, we'll finalize it to provide you with a complete template for integrating UGE into your game:

Let's review the different steps of the code together!

1. Reminder: Initialize the SDK and register a callback

Before Initializing the SDK (which is an asynchronous process), you can register a callback to call subsequent functions of the SDK:

KinetixCore.OnInitialized += OnInitialize;

Then, you can initialize the SDK with the configuration you want:

KinetixCore.Initialize(new KinetixCoreConfiguration()
{
	GameAPIKey = "yourGameAPIKey",
	PlayAutomaticallyAnimationOnAnimators = true,
	EnableAnalytics = true
});

2. Register your local player

Your character has to be an humanoid

To play emotes, you can use an already configured character from your game which has an animator for exemple (custom animation systems are supported, please visit Animation System - Unityfor more info) You can call the RegisterLocalPlayerAnimator method to easily register a character

// Register local player to receive animation
// See "Animation System" documentation
// myAvatarID is optionnal and allows you to play an emote specifically retargeted for your uploaded avatar in the Developer Portal
KinetixCore.Animation.RegisterLocalPlayerAnimator(myAnimator, myAvatarID);

If you uploaded an avatar in our Developer Portal, you can also pass the avatarID matching the player character you registered to benefit from the Contact-Aware Retargeting.

We will focus on this part of the code:

// Now, we connect the current user's account to get his emotes
// The userID is chosen by you, and must be unique to each user
// See "Account Management" documentation
KinetixCore.Account.ConnectAccount(string myConnectedUserID, () => {
	Debug.Log("Account connected successfully");
}, () => {
	Debug.LogError("There was a problem during account connection. Is the GameAPIKey correct?");
});

We use the ConnectAccount method, establishing a link between the user account on your end and within Kinetix's system.

The userID you give to Kinetix must be reused each time you want to connect this specific user, and it must remain exclusive to them.

While it can be a hash or any string, we highly recommend anonymizing user data and refraining from incorporating any personal information.

4. Get ready to use User-Generated Emotes

Let's check the following code (inside the success callback of ConnectAccount)

// You can subscribe to an event to refresh the link when it is expired 
// (after 5 minutes or when an UGE has been submitted with the current token)
KinetixCore.UGC.OnUGCTokenExpired += DisplayUGELink;

DisplayUGELink();

[...]

void DisplayUGELink()
{
    // Example on how to get the link
    KinetixCore.UGC.GetUgcUrl((_Url) {
        // Enable your UI (a button somewhere in you GUI?) here and 
	// assign it the url to the web app
    });
}

As you can see, we provide a way to know when a link / token to the Web Application is invalid (either because of the security token expiration or after usage).

You can then call a method to get the link to the Web Application, and attach it to a script to open the web browser (for example with Application.OpenURL)

5. (After processing) Get the emote of your player

To get your player's emotes, you can call GetUserAnimationMetadatas, which will return an array of AnimationMetadata, containing all the info you will ever need (name, thumbnail, file links, etc...)

As you can see you can get the Id of an emote by accessing the Ids.UUID property of an AnimationMetadata

6. Play the emote

Once we have the id of the emote we want to play (and the local player has been registered), we can just call:

public void PlayEmote(string _MyEmoteID)
{
    	// Finally we can play the animation on our local player
	KinetixCore.Animation.PlayAnimationOnLocalPlayer(_MyEmoteID)
}

You've done it!

You should be ready to use the SDK now! We encourage you to visit SDK Core Modules activation - Unity to expand your knowledge of the SDK or our SDK API Reference - Unityto check what methods are available.

Last updated