Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting current_tab of a tab container doesn't work when it's not visible or not ready #91135

Closed
spiralhalo opened this issue Apr 25, 2024 · 1 comment · Fixed by #91188
Closed
Assignees
Milestone

Comments

@spiralhalo
Copy link

Tested versions

  • Reproducible in: 4.3.dev5
  • Not reproducible in: 4.2.1

System information

Godot v4.3.dev5 - Windows 10.0.19045 - Vulkan (Forward+) - dedicated NVIDIA GeForce RTX 2060 SUPER (NVIDIA; 31.0.15.3118) - Intel(R) Core(TM) i7-8700 CPU @ 3.20GHz (12 Threads)

Issue description

This issue is two-fold (I don't know if I should make separate issues as they seem related):

  • Setting current_tab from script doesn't work when the tab container is not ready. (It works previously) For example, when setting the current_tab from an "uncle" node's _ready() that is higher up in the tree than the parent node.
  • Setting current_tab from script doesn't work in a nested tab container where the target container was not visible, when performed from a button click. select_next_available() doesn't seem to work either.

I noticed this behavior because my project which was working in Godot 4.2.1 no longer works properly in Godot 4.3.dev5 in regards to tab containers.

Setting the current tab in the editor does always seem to work on the other hand.

Current "workaround"

Instead of setting current_tab, setting the tab control's visibility directly seems to work reliably.

Steps to reproduce

Reproduction 1 (not ready)

  • Create 2 sibling nodes, the ordering is important. Attach script to the 1st node, and add a tab container with 2 distinct tabs to the 2nd node. Set the current tab to 0 in the editor inspector.
  • In the 1st node's script's _ready() function, set the tab container's current_tab to 1. It does not work, presumably because the tab container is not ready.
  • In the scene's root node, attach a script and set the tab container's current_tab to 1 in its _ready() function. It does work, presumably because the children are ready, including the tab container.

Reproduction 2 (not visible)

  • Create a nested tab container structure with 1 parent tab container and 2 child tab containers as its tabs. Then add 2 distinct tabs each to the child tab containers. Set the current tab of all tab containers to 0 in the editor inspector.
  • Add a button to the scene's root node. Attach a script in the scene's root node and connect the button's pressed() signal. In the _on_button_pressed() function, set the top tab container's current_tab to 1 then set the 2nd child tab container's current_tab to 1 in the next line.
  • Run the project, click the button once. The top tab container current_tab will change successfully, however the 2nd child's current_tab will fail to change, presumably due to it being previously/currently invisible. Click the button again, now it works because the 2nd child is now visible.

Minimal reproduction project (MRP)

This project contains both reproduction method in separate scenes. Open the scene and run them individually.

  • not_ready_reproduction.tscn for the "not ready" issue reproduction
  • not_visible_reproduction.tscn for the "not visible" issue reproduction

godot4.3.dev5_tab_container_test.zip

@jsjtxietian
Copy link
Contributor

jsjtxietian commented Apr 25, 2024

In the not ready situation, the set_current_tab will be called three times:

  1. instantiate with p_current = 0, but not inside tree, so it set setup_current_tab to 0
  2. called by use's script with p_current = 1
  3. in NOTIFICATION_POST_ENTER_TREE, setup_current_tab >= -1 so the func is called with p_current = 0 ( related to Save current tab in TabBar and TabContainer #83893 )

In the not visible situation, the set_current_tab will be called three times too:

  1. called by use's script with p_current = 1 for the first tab
  2. called by use's script with p_current = 1 for the second tab
  3. callbed by _on_tab_visibility_changed with p_current = 0 ( related to Allow no tabs to be selected in TabBar and TabContainer #87194 )

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

Successfully merging a pull request may close this issue.

4 participants