Button.onClick Obsolete

Hi, today I updated my project from 2021.3 to 2022.3 and get a question.

Here Unity recommend to use Unity UI for runtime:

but here at button say onClick is Obsolete and I should use Ui Toolkit:

So, how do I make a click button at runtime without use Obsolete code?
Should I use Ui Toolkit on every runtime button to avoid get obsolete?

1 Like

You are mixing up documentation for two different buttons from two different UI libraries.

You linked to UnityEngine.UiTools.Button.onClick that is the docs for the version of button from Ui Toolkit. That’s the event which is deprecated. It doesn’t say anything about deprecation of onClick in Unity UI button.

So if you are using Ui Toolkit you have to use clicked instead of onClick.

If you are using Unity UI it doesn’t apply to you. I am guessing that in your code you probably imported the wrong thing and thus got warning about wrong kind of Button and got very confused.

3 Likes

You are right, I mixed the documentation… no i’m not getting any error, i’m just reading.

Still, I was unable to find UnityEngine.UI on documentation 2022

Found this one:
https://docs.unity3d.com/Packages/com.unity.ugui@2.0/api/UnityEngine.UI.Button.html

https://docs.unity3d.com/2022.3/Documentation/ScriptReference/ Contains documentation only for core unity functionality that’s only small fraction of Unity. A lot of Unity functionality is in separate optional packages that can be installed using Unity package manager. Each of those packages often have their own documentation using similar format as one you linked above. You can get the documentation link of most Unity non core packages in the package manager.

9141670--1270063--upload_2023-7-12_16-29-59.png

1 Like