0
\$\begingroup\$

I have created a scroll view in Unity, and wanted to make the elements inside clickable. It would function as a level select menu. The level panels are instantiated from a prefab.

As a first approach I added an IPointerClickHandler to the parent object (the background of the prefab, in grey)

the level prefab

using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;

public class ScrollViewItem : MonoBehaviour, IPointerClickHandler
{
    public TextMeshProUGUI title, length;

    public void initialize(string titleInit, float lengthInit)
    {
        title.text = titleInit;
        length.text = "Length: " + lengthInit.ToString("F0") + "s";
    }

    public void OnPointerClick(PointerEventData eventData)
    {
        Debug.Log("hello");
    }
}

It worked fine until yesterday, and today my Unity editor crashed because of CPU issues I assume, and now this does not work anymore. For some reason the IPointerClickHandler does not react at all, and also if I add a Button to the prefab, the Button stops working as well.

I don't know if it is helpful, but the hierarchy is built as following:

-canvas
--background
---content
----here the panels are instantiated

\$\endgroup\$
5
  • \$\begingroup\$ Can you check if you have an EventSystem in your scene, and that it's configured correctly? It's possible it might have been deleted from your scene or corrupted by whatever caused the crash, or something just before. \$\endgroup\$ Commented Mar 25, 2024 at 18:07
  • \$\begingroup\$ I have an event system added but just the standart one. I'm not quite into this event stuff yet because i am new to coding with unity. \$\endgroup\$ Commented Mar 26, 2024 at 15:27
  • \$\begingroup\$ Does your text have raycast target enabled? If they are children of the parent, its possible they are blocking the interactions. Else, does a button component function at all? \$\endgroup\$ Commented Mar 26, 2024 at 15:36
  • \$\begingroup\$ Button does function, but not if it is instantiated from this ecact prefab. Other prefabs work fine for some reason... I can also click on the grey where there is no text and it still does not work. I assume that this is happening because of the scroll view. \$\endgroup\$ Commented Mar 26, 2024 at 22:26
  • \$\begingroup\$ Check all panels in the hierarchy bottom from your item with IPointerClickHandler. Disable all of them and check if click works. If works mean they blocked click. \$\endgroup\$ Commented Mar 28, 2024 at 21:01

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.