If Viewport.NOTIFICATION_WM_SIZE_CHANGED called every frame no matter what

All in the title, if I use this code :

func _process(_delta: float) → void:
if Viewport.NOTIFICATION_WM_SIZE_CHANGED:
print(“test” )

I get a notification every single frame no matter what, so I guess I don’t understand how this is supposed to work.

NOTIFICATION_WM_SIZE_CHANGED is an int of value 1008, this is not zero so it evaluates to true. you are writing the equivalent of

func _process(_delta: float) -> void:
    if 1008:
        print("test")

You need to override the _notification function and compare to that value.

func _notification(what: int) -> void:
    if what == NOTIFICATION_WM_SIZE_CHANGED:
        print("test")
2 Likes

Ok, I’m even more lost now.
I understand what you’re saying, but I used the code you’re providing and nothing happen.
So I guess I haven’t put it in the right place, the code is in the root object of my scene, which is a Node3D.

is called every frame.
0 reads as false
where numbers greater then 0 read as true.
so NOTIFICATION_WM_SIZE_CHANGED returns 1008
a number greater then 0, so it’s the same as true
if true:
will always be run
so print(“test”) gets run every time _process gets run that’s every frame.

func _notification(what: int) → void:
is like process it’s something called by godot, but not on every frame but when something happens. so if the WM sized changed then godot would do run _notification(1008)

func _notification(what: int) -> void:
    if what == NOTIFICATION_WM_SIZE_CHANGED: #1008 == 1008
        print("test") #the thing you want to do when  NOTIFICATION_WM_SIZE_CHANGED happens.

In the documentation

NOTIFICATION_WM_SIZE_CHANGED = 1008
Notification received when the window is resized.

Note: Only the resized Window node receives this notification, and it’s not propagated to the child nodes.

You might not have great access to this notification, depending on what you are trying to do this snippet may help you more

extends Node3D

func _ready() -> void:
    get_viewport().size_changed.connect(on_window_size_changed)

func on_window_size_changed() -> void:
    print("test")
1 Like

That was the missing piece !
I was on the right track and almost had the right line of code to link the signal, but I’m still struggling a bit with the syntax.

Thanks !

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.