Skip to main content

Configure Game Variables

With Unity Playworks, anyone will be able to create unlimited playable ad variations in a matter of seconds without having to touch your code or rebuild the project.

When preparing your game in Unity, you are able to apply the LunaPlaygroundField or LunaPlaygroundAsset attribute to any serializable field (i.e. public fields of MonoBehaviours and ScriptableObjects or fields marked with SerializeField attribute) and it will be surfaced in the playable editor in Unity Playworks. These fields should be used within your game code so that the default values are overridden when the game is initialised.

Attribute Types

LunaPlaygroundField

This is the most common Unity Playworks Plugin attribute, and should be used for the scriptable game objects you wish to edit from Unity Playworks. For example, you will want to use this for all text and colors for the end card.

  • Supported Types
    • String
    • Integer
    • Float
    • Color
    • Vector2
    • Vector3
    • Vector4
    • Enums
    • Bool
    • Range slider (see below for how to implement)
    • Arrays of the above types (e.g. String[], Int[] etc.)

To see how to set the maximum and minimum length for an array field, click here.

LunaPlaygroundAsset

This should be used when you want to create multiple variations of your ads with different textures or videos, but don't want to increase the overall build size. When using this attribute, you will be able to upload images or videos directly in Unity Playworks. For example, you may wish to change the game icon for your end card.

caution

LunaPlaygroundAssets must be assigned a default value in Unity. Assets without a default value will not be shown in Unity Playworks.

Testing assets fields in the Dev Environment with a Develop build will not work. This field can only be tested in Unity Playworks Hub.

  • Supported Types
    • Image or texture (.png, .jpg, .jpeg)
      • In Unity, please use Texture or Texture2D
    • Audio (.mp3) - This type is supported only after version 3.3.0.
      • In Unity, please use UnityEngine.AudioClip
    • Video (.mp4)
      • In Unity, please use Video.VideoClip
    • Font (.ttf)
      • In Unity, please use UnityEngine.Font
info

Please keep in mind that due to technical specifics of implementation, all instances of a class with variation-controlled fields will receive an updated value. That is fine for Scriptable Objects (because those normally exist as a single instance anyway), but might be a surprise for Mono Behaviours.

For example; referencing the same texture as a LunaPlaygroundAsset in two separate scripts will result in one combined field in Unity Playworks.

LunaPlaygroundFieldStep (Range Slider)

This attribute allows you to define a range of values (min and max) that can be applied to an int or float value, as well as the cardinality of this range (i.e the number of increments).

In Unity Playworks, this will be represented as a slider.

For example:

[LunaPlaygroundFieldStep(0.5f)]
[LunaPlaygroundField("Amount of lives", 1, "Game Settings")]
[Range(0, 10)]
public float someFloat

This will add a range slider to Unity Playworks that allows values inclusively between 0 & 10, and will increment between them by 0.5 at a time.

LunaPlaygroundFieldArrayLength

This attribute allows you to create an array and add/remove values in Unity Playworks, for example, adding new characters to a scene. You must define the the minimum and maximum objects for the array.

For example:

[LunaPlaygroundFieldArrayLength(1, 5)]
[LunaPlaygroundField("Character Names", 1, "Game Settings")]
public string[] characterNames;

This will add an array of strings to Unity Playworks that allows at minimum 1 string, and a maximum of 5.

Implementation

For each LunaPlaygroundField, you can specify the title, group and field order.

[LunaPlaygroundField("Field title", 0, "Group title")]

  • Field title: The name of the field in Unity Playworks i.e. "End card title"
  • Field order: The order of the field in Unity Playworks
  • Field section: The name of the group to which the field belongs i.e. "End Card"

Example

[Header("Playable Ad Settings")]
[SerializeField]
[LunaPlaygroundField("Color of the player", 1, "Player Controls")]
private Color playerColor = Color.blue;

[SerializeField]
[LunaPlaygroundField("Speed of the player", 2, "Player Controls")]
private float playerSpeed = 1f;

[SerializeField]
[LunaPlaygroundField("Number of levels", 3, "Game Controls")]
private int gameLevels = 1;

[SerializeField]
[LunaPlaygroundField("Relative game difficulty", 4, "Game Controls")]
private int gameDifficulty = 3;

[SerializeField]
[LunaPlaygroundAsset("Game Icon", 5, "End Card")]
private Texture gameIconTexture;

[SerializeField]
[LunaPlaygroundAsset("Video Clip", 6, "End Card")]
private VideoClip videoClip;

Playground Sections

The LunaPlaygroundSection attribute can be applied to a class in order to add all Unity Playworks Plugin Fields and Assets into the same Unity Playworks section, making it easier to organise your fields in Unity Playworks.

info

The Playground section will be overridden by the optional parameter, "FieldSection", of a LunaPlaygroundField or LunaPlaygroundAsset attribute.

For example:

[LunaPlaygroundSection("Player Controls", 1)]

public class Player : MonoBehaviour {

[SerializeField]
[LunaPlaygroundField("Color of the player", 1)]
private Color playerColor = Color.blue;


[SerializeField]
[LunaPlaygroundField("Speed of the player", 2)
private float playerSpeed = 1f;
}

We recommend at a minimum, to use the LunaPlaygroundField attribute for:

  • Call to action colors
  • Call to action text values.
  • In-ad messages such as those found in end cards or tutorials.