Skip to content

Reduce redraws in editor - #657

Draft
wjt wants to merge 5 commits into
ramokz:mainfrom
wjt:reduce-redraws-in-editor
Draft

Reduce redraws in editor#657
wjt wants to merge 5 commits into
ramokz:mainfrom
wjt:reduce-redraws-in-editor

Conversation

@wjt

@wjt wjt commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

Fixes #649

wjt added 5 commits May 29, 2026 21:59
Previously `viewfinder.gd`'s `_process()` and `_physics_process()` functions
were called once per frame, regardless of whether the viewfinder panel is
visible. At least one will `return` immediately, depending on the value of
`_physics_based`, and both will return immediately if `_has_pcam_host` is false.

Use `set_process()` and `set_physics_process()` to control which (if either) of
the methods will be called. Update whenever `_has_pcam_host` or `_physics_based`
changes.
Otherwise, the SubViewportContainer gets rerendered once per frame, even when
the panel is closed or there is no pcam in the current scene.
@wjt

wjt commented Jun 2, 2026

Copy link
Copy Markdown
Contributor Author

Draft for 2 reasons:

  1. I've not yet tested this in our game;
  2. I've not tested/fixed 3D because I don't use the 3D side of Godot at all.

manuq pushed a commit to endlessm/threadbare that referenced this pull request Jun 2, 2026
Phantom Camera: Reduce unnecessary processing

Apply the changes I have submitted upstream in
ramokz/phantom-camera#657 to avoid processing
every frame in the editor, even when the open scene does not use
PhantomCamera.

As detailed in that PR and in
ramokz/phantom-camera#649, I haven't figured
out how to avoid the PhantomCameraHost node processing every frame even
when the viewfinder is closed.

And as also detailed there: any inactive PhantomCamera2D still
_process()es every frame, and the PlayerHook has an inactive
PhantomCamera2D, so...

However in most scenes containing the player we have at least one moving
tree or water ripple animation, which causes the scene to render at
60fps anyway. So, oh well!
@ramokz

ramokz commented Jul 13, 2026

Copy link
Copy Markdown
Owner

Just checking in, has the change worked as expected in your 2D project(s)?

@wjt

wjt commented Jul 14, 2026

Copy link
Copy Markdown
Contributor Author

Sort of... I get this warning when switching in the editor from a scene that does not use pcam to a scene which does:

SCRIPT ERROR: Invalid call. Nonexistent function 'get_active_pcam' in base 'Nil'.
          at: _on_update_editor_viewfinder (res://addons/phantom_camera/scripts/panel/viewfinder/viewfinder.gd:552)
          GDScript backtrace (most recent call first):
              [0] _on_update_editor_viewfinder (res://addons/phantom_camera/scripts/panel/viewfinder/viewfinder.gd:552)
              [1] _pcam_priority_override (res://addons/phantom_camera/scripts/phantom_camera_host/phantom_camera_host.gd:1404)
              [2] @priority_override_setter (res://addons/phantom_camera/scripts/phantom_camera/phantom_camera_2d.gd:119)
              [3] _enter_tree (res://addons/phantom_camera/scripts/phantom_camera/phantom_camera_2d.gd:713)

And we also have a strange issue that we have not yet debugged where limits are applied incorrectly when switching camera, but only in (some) exported builds. endlessm/threadbare#2393

I haven't had a chance to test whether these are also reproducible without this stack of patches.

@ramokz

ramokz commented Jul 15, 2026

Copy link
Copy Markdown
Owner

For some reason I cannot replicate the warning you're seeing, but I am encountering an error in update_dead_zone() with those changes:

Invalid type in function '_set_viewfinder' in base 'Control (viewfinder.gd)'.
The Object-derived class of argument 1 (previously freed) is not a subclass of the expected argument class.

Though it's pretty easy to fix by just adding a check and additional assignment.

Another side effect I'm seeing from this PR is when usingFramed Follow while running a scene and having Show Viewfinder in Play enabled where the yellow dot no longer follows its target's position and now stays at the center of the viewport. Digging a bit further it seems like it's because the viewfinder_visible checker returns false in _update_processing().

framed_follow_dot.mp4

And we also have a strange issue that we have not yet debugged where limits are applied incorrectly when switching camera, but only in (some) exported builds. endlessm/threadbare#2393

The issue in that post has been a problem before in general runtime situations (editor included), but should have been fixed quite a while back at this point. But it's very odd that it's seemingly only happening in some build targets and not consistently... My only hunch is the limit bounds are smaller than the PCam2D's viewport and so the camera doesn't quite know where to position itself.
When testing the web build (from the public page on your repo), I cannot repro the issue in that particular spot, but I do see it happening at the bottom of that level. Not sure if anything has changed in that builds compared to the ones you've been testing on:

recording_15_07_26.mp4

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enabling the Phantom Camera plugin forces the godot editor to constantly redraw

2 participants