button color change on click

Naythan 4 months ago in Game Creator updated by Marti (Lead Developer) 4 months ago 10

How can I change a button color when I click it, then change it to another color when I click it again, then again?  It needs to loop from Red, to White, to Blue and back to Red again.  Also, each color will send a different number to a text box.

I'm trying to use a trigger on the button (on mouse left click), which produces the Action (Target: Game Object(Button) Color: Value(Red)) but nothing changes when I click the button.

Unity version:
Game Creator version:

I did a test.

I found that if my trigger is a key press, such as spacebar, I can get a panel to move two steps down.

If I try to use mouse left click to move the panel, it doesn't work.

Is this a bug with mouse left click?

Just add that script into your project and now you have under triggers an OnButtonClick trigger. Then just drag your button into the field of that trigger and then set your  conditions and actions to change the color. Use change graphics color.

Still no go. I'm not a programmer, but that's why I have Game Creator... :)

I can use other triggers, like on start, or on key hold.  But it doesn't do anything if I use a mouse input on the button.

ArgumentException: Object of type 'UnityEngine.Object' cannot be converted to type 'GameCreator.Core.Trigger'.
System.RuntimeType.CheckValue (System.Object value, System.Reflection.Binder binder, System.Globalization.CultureInfo culture, System.Reflection.BindingFlags invokeAttr) (at <437ba245d8404784b9fbab9b439ac908>:0)
System.Reflection.MonoMethod.ConvertValues (System.Reflection.Binder binder, System.Object[] args, System.Reflection.ParameterInfo[] pinfo, System.Globalization.CultureInfo culture, System.Reflection.BindingFlags invokeAttr) (at <437ba245d8404784b9fbab9b439ac908>:0)
System.Reflection.MonoCMethod.DoInvoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at <437ba245d8404784b9fbab9b439ac908>:0)
System.Reflection.MonoCMethod.Invoke (System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at <437ba245d8404784b9fbab9b439ac908>:0)
System.Reflection.ConstructorInfo.Invoke (System.Object[] parameters) (at <437ba245d8404784b9fbab9b439ac908>:0)
UnityEngine.Events.PersistentCall.GetObjectCall (UnityEngine.Object target, System.Reflection.MethodInfo method, UnityEngine.Events.ArgumentCache arguments) (at <23a7799da2e941b88c6db790c607d655>:0)
UnityEngine.Events.PersistentCall.GetRuntimeCall (UnityEngine.Events.UnityEventBase theEvent) (at <23a7799da2e941b88c6db790c607d655>:0)
UnityEngine.Events.PersistentCallGroup.Initialize (UnityEngine.Events.InvokableCallList invokableList, UnityEngine.Events.UnityEventBase unityEventBase) (at <23a7799da2e941b88c6db790c607d655>:0)
UnityEngine.Events.UnityEventBase.RebuildPersistentCallsIfNeeded () (at <23a7799da2e941b88c6db790c607d655>:0)
UnityEngine.Events.UnityEventBase.PrepareInvoke () (at <23a7799da2e941b88c6db790c607d655>:0)
UnityEngine.Events.UnityEvent.Invoke () (at <23a7799da2e941b88c6db790c607d655>:0)
UnityEngine.UI.Button.Press () (at C:/Program Files/Unity/Hub/Editor/2019.3.14f1/Editor/Data/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/UI/Core/Button.cs:68)
UnityEngine.UI.Button.OnPointerClick (UnityEngine.EventSystems.PointerEventData eventData) (at C:/Program Files/Unity/Hub/Editor/2019.3.14f1/Editor/Data/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/UI/Core/Button.cs:110)
UnityEngine.EventSystems.ExecuteEvents.Execute (UnityEngine.EventSystems.IPointerClickHandler handler, UnityEngine.EventSystems.BaseEventData eventData) (at C:/Program Files/Unity/Hub/Editor/2019.3.14f1/Editor/Data/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/EventSystem/ExecuteEvents.cs:50)
UnityEngine.EventSystems.ExecuteEvents.Execute[T] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.ExecuteEvents+EventFunction`1[T1] functor) (at C:/Program Files/Unity/Hub/Editor/2019.3.14f1/Editor/Data/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/EventSystem/ExecuteEvents.cs:261)
UnityEngine.EventSystems.EventSystem:Update() (at C:/Program Files/Unity/Hub/Editor/2019.3.14f1/Editor/Data/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/EventSystem/EventSystem.cs:377)

Did you add that script to your project?

Well, I get no errors and I am using the same GC and Unity version as you.

And the trigger OnButtonClick works.

Maybe I should be using an LTS version of Unity?  Maybe that would help?

I am using 2019.3.14f1 with 2019.3.0f3 my behaviour tree keept crashing when I saved the scene. 

but 2019.3.14f1 works fine for me and had no problems at this moment. OnButtonClick no problem

Seemed to be a problem with the build I had, or something.  Installed the latest LTS version and now it works.  Just have to figure out how to use conditions in my triggers now...

Thank you kindly!!


Make a local or global int counter

Condition if counter 0, then action change graphics color red

action Variable add 1

Condition if counter 1, then change graphics color blue

action Variable add 1

Condition if counter 2, then change graphics color green

action  Variable reset 0


Thanks eagleeyez!