MiTschMR Studios
  • MiTschMR Studios
  • Games
    • Defnite
  • Skills
    • Skills
      • Skills Overview
      • Skills Window
        • Skills
        • Types
        • Settings
      • Skills Component
      • Actions/Conditions/Triggers
      • Skill Tree
      • Skill Bar
      • FAQ
      • Example Setup
      • API Documentation
        • ButtonActionsSkills
          • Classes
            • ButtonActionsEvent
          • Fields
            • actions
            • onClickRight
            • onClick
          • Methods
            • Awake
            • OnValidate
            • OnPointerClick
            • OnSubmit
            • OnFinishSubmit
            • Press
            • PressRight
        • DatabaseSkills
          • Classes
            • SkillsList
              • Fields
                • skills
                • skillTypes
            • SkillSettings
              • Fields
                • skillTreeSelection
                • skillTreeUIPrefabAutomatic
                • skillTreeUIPrefabManual
                • pauseTimeOnUI
                • levelSelection
                • levelVariable
                • levelStat
                • skillPointsSelection
                • skillPointsVariable
                • skillPointsStat
              • Methods
                • GetPauseTimeOnUI
                • GetSkillTreeSelection
                • GetSkillTreeUIPrefabAutomatic
                • GetSkillTreeUIPrefabManual
                • GetLevelSelection
                • GetLevelVariable
                • GetLevelStat
                • GetSkillPointsSelection
                • GetSkillPointsVariable
                • GetSkillPointsStat
              • Enums
                • SkillTreeSelection
                • StatSelection
          • Fields
            • skillList
            • skillsSettings
          • Methods
            • GetSkillList
            • GetSkillListSkillByIndex
            • GetSkillTypes
            • GetSkillTypesTypeByIndex
            • GetSkillSettings
            • GetSkillSuggestions
            • GetSkillTypesNames
            • GetSkillTypesIDs
            • Load
            • InitializeOnLoad
            • GetProjectPath
        • Skill
          • Fields
            • uuid
            • skillName
            • skillDescription
            • icon
            • skillType
            • skillExecutionType
            • castTime
            • executionTime
            • cooldownTime
            • skillState
            • useSkillPoints
            • skillPointsNeeded
            • requiresLevel
            • level
            • reliesOnSkills
            • assignableToSkillBar
            • conditionsExecutionRequirements
            • actionsOnActivate
            • actionsOnCast
            • actionsOnExecute
            • actionsOnFinish
            • conditionsRequirements
            • actionsOnReset
          • Methods
            • CopySkill
            • CopySkillToSkillRelyOn
            • CreateSkillRelyOnInstance
            • UpdateSkillRelyOnInstance
            • DeleteSkillRelyOnInstance
            • CreateSkillInstance
            • OnDestroy
            • DestroyAsset
          • Enums
            • SkillState
            • SkillExecutionType
        • SkillAsset
          • Fields
            • uuid
            • isExecuting
            • isInCooldown
            • cooldownTimeLeft
            • addedToSkillBar
            • addedToSkillBarIndex
            • skillName
            • skillDescription
            • icon
            • skillType
            • skillExecutionType
            • castTime
            • executionTime
            • cooldownTime
            • skillState
            • useSkillPoints
            • skillPointsNeeded
            • requiresLevel
            • level
            • reliesOnSkills
            • assignableToSkillBar
            • conditionsExecutionRequirements
            • actionsOnActivate
            • actionsOnCast
            • actionsOnExecute
            • actionsOnFinish
            • conditionsRequirements
            • actionsOnReset
            • actionsOnResetExecuted
            • onChange
        • SkillBarElement
          • Fields
            • target
            • keyCode
            • skillIcon
            • skillNotAssigned
            • skillCooldownIcon
            • showSkillExecutingIcon
            • skillExecutingIcon
            • showKeyCodeText
            • keyCodeText
            • showExecutingTimeCounter
            • executingTimeCounter
            • showCooldownCounter
            • cooldownCounter
            • showAmountCounter
            • amountCounter
            • skill
            • executer
          • Methods
            • Start
            • Update
            • SetupEvents
            • ExecuteSkill
            • SyncSkill
            • StartSkillExecutionGUI
            • UpdateUI
            • CancelSkillBarSkillExecution
        • SkillBarElements
          • Fields
            • skillBarElements
          • Methods
            • Start
        • SkillBarSkillTreeElement
          • Fields
            • DATABASE_SKILLS
            • keyCode
            • acceptSkillTypes
            • skillIcon
            • skillNotAssigned
            • iconSkillBarConfigurationModeOn
            • iconSkillBarConfigurationModeOff
            • keyCodeText
            • showKeyCodeText
            • allowReplacement
            • allowQuickRemoval
            • skillInConfigurationMode
            • eventOnHoverEnter
            • eventOnHoverExit
            • skill
            • executer
            • skillBarConfigurationModeOn
            • skillTreeUIManager
            • skillBarSkillTreeElementIndex
          • Methods
            • Start
            • Update
            • SetupEvents
            • BindSkill
            • UnbindSkill
            • EnterSkillBarConfigurationMode
            • LeaveSkillBarConfigurationMode
            • RemoveSkillFromSkillBar
            • GetSkill
            • UpdateUI
            • OnPointerEnter
            • OnPointerExit
            • OnDragBegin
            • OnDragEnd
            • OnDragMove
        • SkillBarSkillTreeElements
          • Fields
            • skillBarElements
          • Methods
            • Start
        • SkillContextMenuUI
          • Fields
            • buttonUnlock
            • buttonAddToSkillBar
            • buttonRemoveFromSkillBar
        • SkillHolder
          • Fields
            • skill
          • Methods
            • ToString
        • SkillHolderSerialized
          • Fields
            • skill
          • Methods
            • ToString
        • SkillRelyOn
          • Fields
            • uuid
            • skillName
            • skillDescription
            • icon
            • skillType
            • skillExecutionType
            • castTime
            • executionTime
            • cooldownTime
            • skillState
            • useSkillPoints
            • skillPointsNeeded
            • requiresLevel
            • level
            • assignableToSkillBar
        • SkillTreeItemsUI
          • Fields
            • skills
          • Methods
            • Start
            • UpdateSkills
        • SkillTreeItemsUIAutomatical
          • Fields
            • skillsContainer
            • prefabSkill
            • prefabSkillConnectorEnabled
            • prefabSkillConnectorDisabled
            • distanceBetweenSkillsInLine
            • prefabSkillHolder
            • skillUIHolder
          • Methods
            • UpdateSkills
        • SkillTreeItemsUIManual
        • SkillTreeUIManager
          • Fields
            • TIME_LAYER
            • DATABASE_SKILLS
            • skillTreeAnimator
            • skillTreeRoot
            • isOpen
            • canvasScaler
            • floatingSkillRt
            • skillTreeOpener
            • skillBarElements
            • skillPointsLeft
            • skillsContent
            • floatingSkill
            • skillContextMenu
          • Methods
            • Awake
            • Open
            • Close
            • EnterSkillBarConfigurationMode
            • LeaveSkillBarConfigurationMode
            • SkillRemoveFromSkillBar
            • SetSkillTreeOpenerReferences
            • ResetAllSkills
            • ResetSkill
            • UpdateSkillPoints
            • HideSkillContextMenu
            • UpdateSkillBar
            • OnDragSkill
            • IsOpen
            • ChangeState
            • ResetSkillBar
            • ResetSkillBar
            • GetPointerPositionUnscaled
        • SkillTreeUIManagerAutomatical
          • Fields
            • DEFAULT_UI_PATH
            • skillDistanceFromTop
            • distanceBetweenSkillTypes
            • skillTypeSize
            • skillTypePrefab
            • skillTypes
          • Methods
            • Open
            • OpenSkillTree
            • CloseSkillTree
            • IsSkillTreeOpen
            • RequireInstance
        • SkillTreeUIManagerManual
          • Fields
            • DEFAULT_UI_PATH
          • Methods
            • Open
            • OpenSkillTree
            • CloseSkillTree
            • IsSkillTreeOpen
            • RequireInstance
        • SkillType
          • Fields
            • MAX
            • id
            • name
        • SkillUI
          • Fields
            • DATABASE_SKILLS
            • button
            • skillTreeUIManager
            • skillTreeOpener
            • skillConnectorEnabled
            • skillConnectorDisabled
            • skillIconEnabled
            • skillIconDisabled
            • tooltipIcon
            • tooltipName
            • tooltipDescription
            • tooltipLevelRequiredValue
            • tooltipSkillPointsRequiredValue
            • tooltipSkillStateValue
            • tooltipSkillStateValueColorLocked
            • tooltipSkillStateValueColorUnlocked
            • imageLocked
            • imageUnlocked
            • skillTransform
            • prefabContextMenu
            • skillContextMenu
            • eventOnHoverEnter
            • eventOnHoverExit
          • Methods
            • OnDragBegin
            • OnDragEnd
            • OnDragMove
          • Properties
            • SkillAsset
        • SkillUIAutomatical
          • Fields
            • nameOfSkillTreeUIPrefab
            • skillTreeUIPrefab
          • Methods
            • Setup
            • UpdateUI
        • SkillUIManual
          • Fields
            • skill
          • Methods
            • Setup
            • UpdateUI
        • Skills
          • Classes
            • SerialSkill
              • Fields
            • SerialData
              • Fields
                • skills
            • EventArgs
              • Fields
                • uuid
                • operation
              • Enums
                • Operation
            • EventSkillActivation
            • EventSkillsReset
          • Fields
          • Methods
            • Awake
            • Start
            • OnDestroy
            • GetSkillsDictionary
            • GetSkillPoints
            • GetLevel
            • GetSkill
            • GetSkills
            • GetSkillID
            • GetSkillState
            • GetSkillLockedState
            • GetSkillExecutionState
            • LockSkill
            • UnlockSkill
            • UpdateSkillState
            • CheckSkillRequirements
            • CheckSkillLevel
            • CheckSkillReliesOnSkills
            • CheckSkillOtherConditions
            • CheckSkillSkillPoints
            • ExecuteSkill
            • ExecuteSkillPermanent
            • ExecuteStartActivationPhase
            • ExecuteEndActivationPhase
            • ExecuteStartCastPhase
            • ExecuteEndCastPhase
            • ExecuteStartExecutionPhase
            • ExecuteEndExecutionPhase
            • ExecuteStartFinishPhase
            • ExecuteEndFinishPhase
            • StartCooldown
            • StopCooldown
            • CancelExecutingSkillBar
            • UpdateSkillBar
            • CancelExecutingSkill
            • CancelExecutingSkill
            • CancelExecutingSkills
            • ResetAllSkills
            • ResetSkill
            • ResetSkill
            • SyncSkillBarSkills
            • ChangeSkillType
            • ChangeSkillExecutionSettings
            • ResetPhaseProperties
            • FireResetSkillsEvent
            • AddOnChangeSkill
            • RemoveOnChangeSkill
            • UpdateSkillsList
            • RequireInit
          • Properties
            • IsActivatingSkill
            • IsCastingSkill
            • IsExecutingSkill
            • IsFinishingSkill
        • SkillsSingleSkillTypeAttribute
          • Fields
            • SKILLS
          • Methods
            • OnGUI
  • Finder for Game Creator
    • Finder for Game Creator
      • The Finder Window
        • Triggers
        • Conditions
        • Actions
        • Components
        • Scriptable Objects
      • Extension Installer
  • Finder for Game Creator 2
    • Finder for Game Creator 2
      • The Finder Window
        • Triggers
        • Conditions
        • Actions
        • Components
        • Scriptable Objects
        • Preferences
  • More Extensions
    • List Of My Extensions
  • GC API Guides
    • About
    • Configurable Enter Play Mode Compatibility
    • Access GC Script Components
    • Access Player Using HookPlayer
    • Inventory Custom Entries
    • Accessing Scriptable Objects
    • Custom Editor Windows - Part 1
    • Custom Editor Windows - Part 2
    • Inventory Context Menu Support
    • Inventory Item Tooltips
    • Converting To GC Variables
    • Working With GC Variables
  • C# Code Style Guide
    • C# Code Style Guide For Game Creator
Powered by GitBook
On this page
  • Prerequisites
  • Game Creator Variables
  • Examples

Was this helpful?

  1. GC API Guides

Converting To GC Variables

How to convert normal C# variables to Game Creator Variables

PreviousInventory Item TooltipsNextWorking With GC Variables

Last updated 1 year ago

Was this helpful?

The documentation has moved to:

This version will no longer be updated and maintained.

In this tutorial I want to show you how you can convert normal C# variables to Game Creator variables so you can use the scripts in a more versatile way.

Prerequisites

  • Install Unity

  • Install IDE (I use Visual Studio 2019)

  • Import Game Creator

  • Import the scripts you want to change

Game Creator Variables

Overview

Game Creator has a powerful variable system which I won't explain in details, you can read more about it on the .

The variable system has 9 different types (each linked with a reference what it is):

  • (float)

This means we can convert variables of the these types to their GC variables counterpart.

Code Perspective

From the code perspective, there are two different things we need to take in view. One is the general variables selection, where you can only select a variable and optionally add a filter of which variable types are allowed. The second one is where you specify a fix variable type and allow the option of adding a value of this type as well (not only GC variables). Let's take a look at the first one:

using UnityEngine;
using GameCreator.Variables;

public class GCVariablesTutorial : MonoBehaviour
{
    public VariableProperty variable = new VariableProperty();
}

This little script gives us this result:

Let's take a look at the code:

  • When working with the Game Creator variable system, you need to add the GameCreator.Variables namespace at the top

  • The class VariableProperty is a generic variable class that allows you to select any variable of any type, may that be a global, local or list one

As I have written before, you can apply a filter to this type of variable. For this, you need to add this code: [VariableFilter(Variable.DataType.<VariableType>)], where <VariableType> is one of the types mentioned in the overview. Your scripting solution (IDE) should suggest them to you if you don't know them anymore. Let's say, we want to add a filter to only include GameObject variables, the code looks like this:

using UnityEngine;
using GameCreator.Variables;

public class GCVariablesTutorial : MonoBehaviour
{
    [VariableFilter(Variable.DataType.GameObject)]
    public VariableProperty variable = new VariableProperty();
}

With the selection now looking like this:

We only have one GameObject variable in our global variables, so that's correct.

Now for the second part (which is most likely the more interesting one for you), for each variable type mentioned in the overview, Game Creator has a type that let's you specify a value of this type or a global, local or list variable value. Here you can see what I mean:

In the dropdown, additional to the usual Use Global/Local/List Variable you have the entry Value, which is what I am talking about. The code is this one:

using UnityEngine;
using GameCreator.Variables;

public class GCVariablesTutorial : MonoBehaviour
{
    public GameObjectProperty goVariable = new GameObjectProperty();
}

I have replaced VariableProperty with GameObjectProperty. There are the following classes you can use:

  • BoolProperty

  • ColorProperty

  • NumberProperty

  • GameObjectProperty

  • SpriteProperty

  • StringProperty

  • Texture2DProperty

  • Vector2Property

  • Vector3Property

When you select the dropdown value for selecting a variable and not the Value entry, Game Creator already filters for exactly this type of variable so you can not choose anything else that does not fit.

Variables Access

Getting back to the first type of variables, if you need to access a VariableProperty, you need to call the method Get(invoker), where the optional parameter invoker is of type GameObject and usually the gameobject the script is on. Of course you can also set the invoker to null (which means empty). If we take a look at the previous example of the GameObject, it looks like this:

using UnityEngine;
using GameCreator.Variables;

public class GCVariablesTutorial : MonoBehaviour
{
    [VariableFilter(Variable.DataType.GameObject)]
    public VariableProperty variable = new VariableProperty();

    private void Start()
    {
        // Without invoker parameter.
        GameObject go = (GameObject)this.variable.Get();
        
        // With invoker parameter set to this gameobject.
        GameObject go2 = (GameObject)this.variable.Get(this.gameobject);
        
        // With null invoker parameter set to null.
        GameObject go3 = (GameObject)this.variable.Get(null);
    }
}

Getting back to the second type of variables, we again take the example of the GameObject, but this time we use GameObjectProperty:

using UnityEngine;
using GameCreator.Variables;

public class GCVariablesTutorial : MonoBehaviour
{
    public GameObjectProperty goVariable = new GameObjectProperty();

    private void Start()
    {
        // With invoker parameter set to this gameobject.
        GameObject go = this.goVariable.GetValue(this.gameObject);

        // With invoker parameter set to null.
        GameObject go2 = this.goVariable.GetValue(null);
    }
}

Using the BaseProperty<T>.GetValue() (BaseProperty<T> is the base class of all GC variable classes) method we directly get the value already converted (casted) to the desired type. For instance, you use the NumberProperty class, you get a float value when using the GetValue() method. Note that we can not use this method without the invoker parameter, as this way is now obsolete and no longer supported, it may be removed in the future.

For the variable types BoolProperty, ColorProperty, NumberProperty, StringProperty, Vector2Property and Vector3Property you can set values in the ( ) brackets if desired.

Examples

#1

In this example, we convert three variables (float, GameObject, Color) to their GC counterpart so that we can still set our own values.

Original code:

using UnityEngine;

public class GCVariablesTutorial : MonoBehaviour
{
    public float number = 1;
    public GameObject go;
    public Color color = Color.red;
}

Original inspector:

New code:

using UnityEngine;
using GameCreator.Variables;

public class GCVariablesTutorial : MonoBehaviour
{
    public NumberProperty number = new NumberProperty(1);
    public GameObjectProperty go = new GameObjectProperty();
    public ColorProperty color = new ColorProperty(Color.red);
}

New inspector:

#2

This example focuses on converting a "Graphic" variable to support selecting the target from a Game Creator variable:

Original code:

public class ActionGraphicColor : IAction
{
	public Graphic graphic;

	[Range(0.0f, 10.0f)]
	public float duration = 0.0f;

	public ColorProperty color = new ColorProperty(Color.white);

	// EXECUTABLE: ----------------------------------------------------------------------------

	public override bool InstantExecute(GameObject target, IAction[] actions, int index)
	{
		if (this.duration <= 0.0f)
		{
			if (this.graphic != null) this.graphic.color = this.color.GetValue(target);
			return true;
		}

		return false;
	}

	public override IEnumerator Execute(GameObject target, IAction[] actions, int index)
	{
		if (this.graphic != null)
		{
			Color currentColor = this.graphic.color;
			Color targetColor = this.color.GetValue(target);

			float startTime = Time.unscaledTime;
			WaitUntil waitUntil = new WaitUntil(() =>
			{
				float t = (Time.unscaledTime - startTime) / this.duration;
				this.graphic.color = Color.Lerp(currentColor, targetColor, t);

				return t > 1.0f;
			});

			yield return waitUntil;
			this.graphic.color = targetColor;
		}

		yield return 0;
	}
	
	// More code to come, but inspector related, not important for this example.

Original inspector:

New code:

public class ActionGraphicColor : IAction
{
	public GameObjectProperty graphic = new GameObjectProperty();
	[Range(0.0f, 10.0f)]
	public float duration = 0.0f;

	public ColorProperty color = new ColorProperty(Color.white);

	// EXECUTABLE: ----------------------------------------------------------------------------

	public override bool InstantExecute(GameObject target, IAction[] actions, int index)
	{
		if (this.duration <= 0.0f)
		{
			if (this.graphic != null) this.graphic.GetValue(target).GetComponent<Graphic>().color = this.color.GetValue(target);
			return true;
		}

		return false;
	}

	public override IEnumerator Execute(GameObject target, IAction[] actions, int index)
	{
		if (this.graphic != null)
		{
			Color currentColor = this.graphic.GetValue(target).GetComponent<Graphic>().color;
			Color targetColor = this.color.GetValue(target);

			float startTime = Time.unscaledTime;
			WaitUntil waitUntil = new WaitUntil(() =>
			{
				float t = (Time.unscaledTime - startTime) / this.duration;
				this.graphic.GetValue(target).GetComponent<Graphic>().color = Color.Lerp(currentColor, targetColor, t);

				return t > 1.0f;
			});

			yield return waitUntil;
			this.graphic.GetValue(target).GetComponent<Graphic>().color = targetColor;
		}

		yield return 0;
	}
	
	// More code to come, but inspector related, not important for this example.

Sharp eyes see the difference. Because the Game Creator variable we use is of type GameObject we have to get the Graphic component and apply the the settings to there.

// Old code to access the graphic variable.
this.graphic

// Replaced with.
this.graphic.GetValue(target).GetComponent<Graphic>()

// ----------------------------

// Old code to access the color property of the graphic variable.
this.graphic.color

// Replaced with.
this.graphic.GetValue(target).GetComponent<Graphic>().color

Even though there is already a page on the about this topic, it does not cover everything that I am talking about in this guide. That's why there is additional information following.

You may wonder what the (GameObject) means. The VariableProperty.Get() method returns an object of type , which we can not use directly. In order for us to use it, we need to convert (cast) it to the desired type (in this case GameObject).

https://mitschmr-studios.io/documentation/api-guides/convertingtogcvariables.html
offical site
Bool
Color
Number
GameObject
Sprite
String
Texture2D
Vector2
Vector3
official documentation
object