Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Michael_Effraimidis · Jan 28 at 06:31 PM · guigridlayout

Grid layout lags after thousand inserts.

Hello everyone,

I'm trying to make a table using a grid layout. There are many tutorials on youtube showcasing how to do it and I basically insert a prefab white image with altered text whenever I need to populate a table. I also added a vertical scroll to be able to scroll each tab. Furthermore I added a toggle and a button script on each tab using RectTransform.SetAsLastSibling() to bring the respective tab in front.

alt text

The problem is that after a few hundred insertions on a tab the performance drops dramatically. At about 1000 insertions the table because sluggishly slow and is not good for use.

This is the code for the insertions (It's based on a postgres npgsql dll plugin)

 using System;
 using System.Collections.Generic;
 using UnityEngine;
 using Npgsql;
 using UnityEngine.UI;

 public class DBConnection : MonoBehaviour
 {
     private NpgsqlConnection conn;
 
     public bool Connected=false;
 
     // Start is called before the first frame update
     void Start()
     {
         
     }
 
     // Update is called once per frame
     void Update()
     {
         //should check here if the connection is active or down
     }
     public void Connect_Database()
     {
         // connection config
         string server = "****";
         string port = ""****";
         string database = ""****";
         string user = ""****";
         string password = ""****";
 
         // connection string format
         string connstring = String.Format($"Server={server};" +
             $"Port={port};" +
             $"Database={database};" +
             $"User Id={user};" +
             $"Password={password};");
 
         // attempt to connect to database
         Debug.Log("Connect String = " + connstring);
         try
         {
             // Making connection with Npgsql provider
             conn = new NpgsqlConnection(connstring);
             Debug.Log("Connected" + conn);
             
             conn.Open();
             Debug.Log("connection established");
 
             Connected = true;
         }
         catch (Exception e)
         {
             Debug.LogError($"Could not establish a connection, reason:{e}");
             Connected = false;
 
             throw;
         }
     }
 
     public List<string> Select_Pelatologio()
     {
         string sql = "SELECT * FROM Πελατολόγιο";
         return Select_Query(sql);
     }
 
     public List<string> Select_Peristatika()
     {
         string sql = "SELECT * FROM Περιστατικά limit 800";
         return Select_Query(sql);
     }
 
     public List<string> Select_Query(string query)
     {
         List<string> result_query = new List<string>();
         NpgsqlCommand cmd = new NpgsqlCommand(query, conn);
 
         NpgsqlDataReader dr = cmd.ExecuteReader();
         Debug.LogFormat($"Attempting to run query:{query}");
 
         // insert all items into the grid
         while (dr.Read())
         {
             string tmp = "";
             for (int i = 0; i < dr.FieldCount; i++)
             {
                 //tmp = ;
                 tmp += ($"{dr[i].ToString()}\t");
                 result_query.Add(dr[i].ToString());
             }
 
             Debug.Log($"{tmp}\n");
         }
         Debug.Log("Query finished");
         
         dr.Close();
         
         return result_query;
     }
 }


The grid code is this:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 
 public class Grid_Pelatologio : MonoBehaviour
 {
     public GameObject Prefab;
     //public int NumberToCreate;
     public GridLayoutGroup GridLayoutGroup;
     public GameObject Content;
 
     // Start is called before the first frame update
     void Start()
     {
         Clear_All();
     }
 
     void Update()
     {
 
     }
     public void Clear_All()
     {
         foreach (Transform child in this.transform)
         {
             Destroy(child.gameObject);
         }
     }
     public void Add_Random_Color(GameObject obj)
     {
         obj.GetComponent<Image>().color = Random.ColorHSV();
     }
 
     public void Insert_Items(List<string> items)
     {
         for (int i = 0; i < items.Count; i++)
         {
             GameObject obj = Instantiate(Prefab, Content.transform);
             obj.GetComponentInChildren<Text>().text = items[i];
         }
     }
     public void Insert_Item(string item)
     {
         GameObject obj = Instantiate(Prefab, Content.transform);
         obj.GetComponentInChildren<Text>().text = item.ToString();
     }
     IEnumerator ChangeGridSize(int x, int y)
     {
         yield return new WaitForSeconds(2);
         // Now do your thing here
     }
 }


What am I doing wrong? Thanks for your time and I'll gladly answer any specifications you ask.

new-bitmap-image.jpg (343.5 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

212 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to assign textures to specific grid locations? 2 Answers

Gui Layout Interface 0 Answers

Grid Layout spacing not working when in Android Build 0 Answers

Snap guides for laying out objects 2 Answers

how to make grid of buttons always fit parent? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges