Skip to content

Unable to resize through code after docking a panel #23

Open

Description

@Rhitomaic

Description of the bug

So I tried to dock a RectTransform using code and it doesn't seem to resize properly, it's stuck at MinSize still even though I don't want it to start at MinSize,

Despite debugging making sure the Vector2 I used is correct, the panel is still resized towards it's minimum size
Image

Reproduction steps

Here's the code I'm using

using DynamicPanels;
using UnityEngine;

namespace Rhitomata {
    public class GameUI : MonoBehaviour {
        public DynamicPanelsCanvas dynamicCanvas;

        [Header("Timeline")]
        public RectTransform timelinePanel;
        public Vector2 timelineMinSize = new(200f, 100f);
        [HideInInspector] public Panel dynamicTimelinePanel;
        [HideInInspector] public PanelTab dynamicTimelinePanelTab;

        private void Awake() {
            // Timeline
            var previousTimelineSize = timelinePanel.rect.size;
            dynamicTimelinePanel = PanelUtils.CreatePanelFor(timelinePanel, dynamicCanvas);
            dynamicTimelinePanel.DockToRoot(Direction.Bottom);
            dynamicTimelinePanelTab = PanelUtils.GetAssociatedTab(timelinePanel);
            dynamicTimelinePanelTab.MinSize = timelineMinSize;
            dynamicTimelinePanelTab.Icon = null;
            dynamicTimelinePanelTab.Label = "Timeline";
            dynamicTimelinePanel.ResizeTo(previousTimelineSize);
        }
    }
}

Platform specs

Please provide the following info if this is a Unity 3D repository.

  • Unity version: 6000.0.51f1
  • Platform: Unity Editor
  • Device: Lenovo Thinkpad L15 Gen 1
  • How did you download the plugin: GitHub

Additional info
None

Activity

  1. yasirkula commented on Jul 24, 2025

    @yasirkula
    Owner

    DynamicPanelsCanvas builds its layout in Start:

    private void Start()
    {
    Size = RectTransform.rect.size;
    HashSet<Transform> createdTabs = new HashSet<Transform>(); // A set to prevent duplicate tabs or to prevent making canvas itself a panel
    Transform tr = transform;
    while( tr )
    {
    createdTabs.Add( tr );
    tr = tr.parent;
    }
    Dictionary<Panel, Vector2> initialSizes = null;
    if( initialPanelsAnchored != null )
    {
    initialSizes = new Dictionary<Panel, Vector2>( initialPanelsAnchoredSerialized.Count );
    CreateAnchoredPanelsRecursively( initialPanelsAnchored.subPanels, dummyPanel, createdTabs, initialSizes );
    }
    for( int i = 0; i < initialPanelsUnanchored.Count; i++ )
    CreateInitialPanel( initialPanelsUnanchored[i], null, Direction.None, createdTabs );
    initialPanelsUnanchored = null;
    initialPanelsAnchored = null;
    initialPanelsAnchoredSerialized = null;
    if( freeSpaceTargetTransform )
    {
    if( freeSpaceTargetTransform.parent != RectTransform )
    freeSpaceTargetTransform.SetParent( RectTransform, false );
    freeSpaceTargetTransform.anchorMin = Vector2.zero;
    freeSpaceTargetTransform.anchorMax = Vector2.zero;
    freeSpaceTargetTransform.pivot = Vector2.zero;
    freeSpaceTargetTransform.SetAsFirstSibling();
    }
    LeaveFreeSpace = m_leaveFreeSpace;
    LateUpdate(); // Update layout
    if( m_leaveFreeSpace )
    {
    // Minimize all panels to their minimum size
    dummyPanel.ResizeTo( new Vector2( 99999f, 99999f ) );
    //RootPanelGroup.Internal.TryChangeSizeOf( dummyPanel, Direction.Left, 20009f );
    //RootPanelGroup.Internal.TryChangeSizeOf( dummyPanel, Direction.Top, 20009f ); // Magick number..
    //RootPanelGroup.Internal.TryChangeSizeOf( dummyPanel, Direction.Right, 20009f ); // or not?
    //RootPanelGroup.Internal.TryChangeSizeOf( dummyPanel, Direction.Bottom, 20009f ); // A: just a big random number U_U
    }
    if( initialSizes != null )
    ResizeAnchoredPanelsRecursively( RootPanelGroup, initialSizes );
    }

    It might be possible that this process overrides your code that is inside Awake (which is invoked before Start). Could you try executing your code in Start?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions