Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Unity UI [Solved]ScrollView with toggle as children with delegate in method creates 27 cubes

Discussion in 'UGUI & TextMesh Pro' started by Faic, Jun 23, 2018.

  1. Faic

    Faic

    Joined:
    Jun 2, 2015
    Posts:
    19
    Following insanely weird problem.

    To replicate (Sometimes?):
    1. Create ScrollView
    2. Add toggle in content
    3. Give toggle a method which contains a delegate
    4. As soon as you toggle the toggle it will create 27 cubes
    Further information:
    • I use it in a 2D project.
    • The amount of toggles does not increase the amount of cubes
    • Updating anything in the toggle on start or update triggers the creation of the cubes
    • Does not happen with buttons
    • I now removed the method from the toggle and the problem still occurs, 2min ago by adding and removing it the problem also occured or not. Seems like this is just a part of it.

    My method with a delegate for example is
    Code (CSharp):
    1.  Text infoText;
    2.  
    3.     void Start()
    4.     {
    5.         infoText = GameObject.Find("UIInfoTextMissions").GetComponent<Text>();
    6.         Toggle t = GetComponent<Toggle>();
    7.         t.onValueChanged.AddListener(delegate
    8.         {
    9.             ChangeMapDesciption(t);
    10.         });
    11.  
    12.     }
    13.  
    14.     void ChangeMapDesciption(Toggle change)
    15.     {
    16.         if (change.isOn == true)
    17.         {
    18.             infoText.text = ContentStuff.maps[int.Parse(change.gameObject.name)].info;
    19.             Camera.main.GetComponent<GameLogic>().SetCurrentMap(int.Parse(change.gameObject.name));
    20.         }
    21.  
    22.     }
    I have no idea why this happens but it's a extremly weird bug.
     
    Last edited: Jun 23, 2018
  2. Faic

    Faic

    Joined:
    Jun 2, 2015
    Posts:
    19
    Found the problem.

    In one of my static classes was a create primitive method. For whatever reason this was only executed when I toggled a toggle with a delegate in a scrollviewer even though there is no connection between them at all. With called I mean initalized. It is an array and the constructor created the primitive.