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

SubViewport.size_2d_override does nothing when set in scene's _ready function #68871

Closed
AaronWizard opened this issue Nov 19, 2022 · 2 comments · Fixed by #67331
Closed

SubViewport.size_2d_override does nothing when set in scene's _ready function #68871

AaronWizard opened this issue Nov 19, 2022 · 2 comments · Fixed by #67331

Comments

@AaronWizard
Copy link

AaronWizard commented Nov 19, 2022

Godot version

4.0.beta5.official (89a33d2)

System information

macOS 13.0.1

Issue description

I have a scene with a SubViewport in a SubViewportContainer. In the scene's _ready function I am attempting to set the SubViewport's size_2d_override property to a value smaller than the SubViewport/SubViewportContainer's size. e.g. The SubViewport's size is 512x512, while I'm setting it's size_2d_override to 100x100. This has no affect when the game runs; any children of the SubViewport are not scaled down properly.

This works fine if I set size_2d_override in the SubViewport's inspector. It also works fine if I resize it during the root's size_changed event.

Steps to reproduce

  1. Create a new scene.
  2. Add a SubViewportContainer to the scene root.
  3. Add SubViewport to the SubViewportContainer.
  4. Add a Sprite2D to the SubViewport.
    Screenshot 2022-11-18 at 10 54 11 PM
  5. In the SubViewport's inspector, set its size to 512x512 and set "Size 2D Override Stretch" to true. Do not set values for "Size 2D Override".
    Screenshot 2022-11-18 at 10 55 02 PM
  6. Add this script to the root node:
extends Node

@onready var _viewport: SubViewport = $SubViewportContainer/SubViewport

func _ready() -> void:
    _viewport.size_2d_override = Vector2i(100, 100)

Expected Result: When the project is run, the sprite inside the SubViewport is scaled to reflect its size_2d_override.
Screenshot 2022-11-18 at 10 58 57 PM

Actual Result: No scaling is applied to the sprite.
Screenshot 2022-11-18 at 10 59 50 PM

Minimal reproduction project

ViewportTest.zip

@Sauermann
Copy link
Contributor

Sauermann commented Nov 19, 2022

Workaround until the fix gets merged is to set it twice:

func _ready() -> void:
	for i in 2:
		_viewport.size_2d_override = Vector2i(100, 100)

@golddotasksquestions
Copy link

golddotasksquestions commented Dec 2, 2022

If someone who find this issue tries to do this (low res SubViewport in a high res game) in the editor, I listed the steps to follow here in the Reddit post.

@clayjohn clayjohn modified the milestones: 4.0, 4.x Jan 12, 2023
@akien-mga akien-mga modified the milestones: 4.x, 4.0 Feb 1, 2023
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.

6 participants