Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

116
Views
Custom onClick list

Can i create custom region with grouped methods for list onClick like dynamic and statics? like this

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Yes and no! ^^

  • Yes, you can create your own event type taking a parameter and assign dynamic callbacks to it. What you are looking for is UnityEvent.

    For the dynamic parameterized ones see UnityEvent<T0> to UnityEvent<T0, T1, T2, T3> depending on how many parameters you need.

    For the example with a single int it would be (exactly as in the API example)

    // Since Unity doesn't support direct serialization of generics you have to implement this [Serializable] wrapper
    [Serializable]
    public class MyIntEvent : UnityEvent<int>
    {
    }
    
    public class ExampleClass : MonoBehaviour
    {
        public MyIntEvent m_MyEvent;
    }
    

    enter image description here

  • No, you can not simply change the existing implementation of UI.Button.onClick which is parameterless.

    What you could do, however, is build a new component and attach it on a button like

    [RequireComponent(typeof(Button))]
    public class ExampleClass : MonoBehaviour
    {
        [SerializeField] private Button _button;
        public MyIntEvent onClickWithIntParameter;
    
        private void Awake()
        {
            if(!_button) _button = GetComponent<Button>();
            _button.onClick.AddListener(HandleOnClick);
        }
    
        private void HandleOnClick()
        {
            // Wherever you get your int from
            var value = 123;
    
            onClickWithIntParameter.Invoke(value);
        }
    }
    
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!