I'm using responsive containers in a grid/table layout, typically with 50 rows and 12 columns. Each cell is also a Responsive container. Once the initial sizes are determined the sizes do not change (or change rarely), even though the image in the cell may change.

However, since Update() is always calling Resize(), and resize is always calculating sizes, this causes a real performance issue.

  1. Is there a way that Responsive Container can detect changes and only do the resize calculations if something has changed?
  2. Or maybe not actually setting a size if nothing has changed will help, as then the canvas won't be marked dirty?

FYI, I have worked around this to some extent by only doing the resize calculations every 12 frames (200 ms @ 60 FPS).

    dtappe Hi! Thanks for the feedback, I will add refresh options : Update/Every X Seconds/On Change/Manual.
    I will keep you posted!

      I submitted the update to the asset store, it will be available soon 😉

        19 days later

        Anthony
        dtappe

        Hi, I have a similar issue, where I add and remove ResponsiveContainer child components.
        Don't know if this helps but I made these changes that currently solves my issue.
        and also prevents continuous Resize() update calls.

        Update to ResponsiveItem.cs

            [ExecuteAlways]
            public class ResponsiveItem : MonoBehaviour
            {
                public ResponsiveContainer.ResponsiveItemData settings;
        
                private void OnEnable()
                {
                    InvokeParentsOnTransformChildrenChanged();
                }
        
                private void OnDisable()
                {
                    InvokeParentsOnTransformChildrenChanged();
                }
                
                private void OnRectTransformDimensionsChange()
                {
                    InvokeParentsOnTransformChildrenChanged();
                }
        
                private void InvokeParentsOnTransformChildrenChanged()
                {
                    var containers = GetComponentsInParent<ResponsiveContainer>();
                    foreach (var container in containers)
                    {
                        container.OnTransformChildrenChanged();
                    }
                }
            }

        Update to ResponsiveContainer.cs (line 52 to 71) in v1.0.2

                void Start()
                {
                    Init();
                    Resize(!Application.isPlaying);
                }
        
                private bool transformChildrenChanged;
                public void OnTransformChildrenChanged()
                {
                    if (container != null)
                    {
                        activeChildren = GetChildrenFirstDepth(container);
                        activeChildCount = activeChildren.Count;
                    }
        
                    transformChildrenChanged = true;
                }
        
                /// <summary>
                /// Initialize the component
                /// </summary>
                private void Init()
                {
                    container = GetComponent<RectTransform>();
                    activeChildren = GetChildrenFirstDepth(container);
                    activeChildCount = activeChildren.Count;
                }
        
                void Update()
                {
                    if (!transformChildrenChanged)
                        return;
                    transformChildrenChanged = false;
                    
                    // Force resize only when not playing
                    Resize(!Application.isPlaying);
                }

        Oh. PS.
        I added a "Assembly Definition" - Exoa.Responsive.asmdef to the Exoa -> ResponsiveUI root folder.
        this was required to add it as a Assembly Definition Reference in one of my project files that also has it's own Assembly Definition.

          5 days later

          Tinus Thank you that's a nice implementation! In the last release, I added an option to Resize() only when there is a change happening (active children count and sizes) so that should work as well.

          Thanks

            a month later

            Anthony, Sorry for the delay... I tried to install the latest version 1.0.2. After import, I could not find the changes related to
            "Improved performances with different refresh settings (On Change/On Rate/On Update/Manual)"

            There were only 2 file changes. The one script file that changed was ResponsiveContainer.cs, and it just had to lines changed. The other change was for Demo_Fit_Expand.unity.meta, a GUID change.

              Anthony, Sorry for the delay... I tried to install the latest version 1.0.2. After import, I could not find the changes related to
              "Improved performances with different refresh settings (On Change/On Rate/On Update/Manual)"

              There were only 2 file changes. The one script file that changed was ResponsiveContainer.cs, and it just had to lines changed. The other change was for Demo_Fit_Expand.unity.meta, a GUID change.

                Anthony , Sorry for the delay... I tried to install the latest version 1.0.2. After import, I could not find the changes related to
                "Improved performances with different refresh settings (On Change/On Rate/On Update/Manual)"

                There were only 2 file changes. The one script file that changed was ResponsiveContainer.cs, and it just had to lines changed. The other change was for Demo_Fit_Expand.unity.meta, a GUID change.

                  dtappe Do you see this code inside your version of Responsive Container ?

                  [Header("REFRESH")]
                  public RefreshType refreshType;
                  public enum RefreshType { OnChange, OnRate, OnUpdate, Manual };
                  public float refreshRate = 1f;
                  private float lastRefresh;
                  private float lastRefreshChangeValue;

                  If you do you should see a REFRESH section on any responsive container component in the inspector. If you don't I could have screwed the update on the asset store.

                  Let me know thanks!

                    dtappe Ok thanks for letting me know, I just submitted it again (1.0.2b), it should be available within 2 days.

                    Keep me posted
                    Thanks!

                      Write a Reply...