GodotVCamera icon indicating copy to clipboard operation
GodotVCamera copied to clipboard

Optional preview of TransformModifier's effect

Open aXu-AP opened this issue 2 years ago • 2 comments

Is your feature request related to a problem? Please describe. Having TransformModifier work in tool mode is great for understanding how they work and get immediate feedback from tinkering parameters. However it comes with a caveat: they may make unwanted changes to a scene (which can lead to unnecessary dif lines on version control). Also there doesn't seem to be logic in this: some modifiers like LookAt and Follow do live preview, while Shake and LookAtGroup don't.

Describe the solution you'd like All modifiers should include and implement editor_preview export in them. This way one can tinker with modifiers and get realtime feedback, but turn preview off when they are satisfied with the solution. For now this is the most elegant solution I've come up:

# TransformModifier.gd
export var editor_preview : bool = true

func is_modifier_enabled() -> bool:
	return editor_preview or not Engine.editor_hint

# Shake.gd
func _physics_process(delta: float) -> void:
	if .is_modifier_enabled():
		# modifier logic here

Describe alternatives you've considered Some modifiers are stable as long as their targets don't move. These might be safe to have live preview on all times. However that doesn't solve the problem for the rest of the modifiers.

Additional context I also tried to move the actual logic into virtual function (_apply_modifier) which base class would call on their _physics_process, but found out that base class's _physics_process doesn't get called in derived classes.

An unrelated small question about coding style: is there some advantage in that inheritance is declared with path instead of class name? ie. extends "res://addons/virtualcamera/TransformModifiers/TransformModifier.gd" instead of extends TransformModifier? To me latter seems cleaner, but I've followed established style.

aXu-AP avatar May 29 '22 19:05 aXu-AP

The main reason I've been using the path explicitly for inheritance is that it's less error prone. I've had issues where scripts will think there's a cyclic dependency or compilation error if it's using a custom class_name until the project is reloaded.

Bryce-Dixon avatar May 29 '22 22:05 Bryce-Dixon

Ok nice to know. Inheritance in gdscript does sometimes have its problems...

aXu-AP avatar May 30 '22 06:05 aXu-AP