/// <summary>
        /// Retrieves the value of the variable as a System.Object
        /// </summary>
        /// <param name="name">The name of the variable to retrieve</param>
        /// <returns>The value of the variable</returns>
        /// <exception cref="KeyNotFoundException">Thrown if the variable isn't found</exception>
        public System.Object GetObjectValue(string name)
        {
            SceneVariable foundVariable = GetVariable(name);

            if (foundVariable == null)
            {
                throw new KeyNotFoundException("Variable " + name + "doesn't exist");
            }

            return(foundVariable.GetValue());
        }
        /// <summary>
        /// Creates a new scene variable
        /// </summary>
        /// <param name="name">The name to give the variable</param>
        /// <param name="valueContainer">The container of the value it will store</param>
        public void CreateNewVariable(string name, ScriptableObject valueContainer)
        {
            if (!(valueContainer is IVariable))
            {
                throw new ArgumentException("Provided value container is not an IVariable, cannot create Scene Variable");
            }

            SceneVariable newVar = new SceneVariable()
            {
                Name = name
            };

            newVar.SetContainer(valueContainer);

            AddVariable(newVar, false);
        }
        /// <summary>
        /// Adds a variable to the collection
        /// </summary>
        /// <param name="variable">The variable to add</param>
        /// <param name="overwriteIfExist">True to overwrite if a variable of the name already
        /// exists, false to ignore</param>
        internal void AddVariable(SceneVariable variable, bool overwriteIfExist = false)
        {
            if (DoesVariableExist(variable.Name))
            {
                if (overwriteIfExist)
                {
                    sceneVariables.RemoveAll((x) => x.Name == variable.Name);
                }
                else
                {
                    return;
                }
            }

            sceneVariables.Add(variable);
        }
        /// <summary>
        /// Sets the value of the specified variable
        /// </summary>
        /// <param name="name">The name of the variable to be set</param>
        /// <param name="newValue">The value to assign to the variable</param>
        public void SetValue(string name, System.Object newValue)
        {
            SceneVariable foundVariable = GetVariable(name);

            if (foundVariable == null)
            {
                throw new KeyNotFoundException("Variable " + name + " doesn't exist");
            }

            System.Object oldValue = foundVariable.GetValue();

            if (oldValue.Equals(newValue))
            {
                return;
            }

            foundVariable.SetValue(newValue);

            OnVariableChanged.SafeInvoke(this, new EventArgs <string>()
            {
                Value = name
            });
        }
 /// <summary>
 /// Remove the variable
 /// </summary>
 /// <param name="variable">The variable to remove</param>
 internal void RemoveVariable(SceneVariable variable)
 {
     sceneVariables.Remove(variable);
 }