I’ve some platformer code to make my character leap based mostly on peak. I would like to have the ability to tune it within the editor utilizing each world models or variety of tiles. I can do that with setters:
extends CharacterBody2D
const TILE_SIZE := 16.0
@export_group("Leap Motion")
## Peak in world models.
@export_range(1, 160) var jump_height: float = TILE_SIZE * 4
## Peak in tile depend.
@export_range(1, 10, 0.25) var jump_tiles: float = 4:
get:
return jump_height / TILE_SIZE
set(worth):
jump_height = worth * TILE_SIZE
@export var jump_speed: float:
get:
return calc_jump_speed()
@export_range(0, 9999) var gravity: float = 3840
func calc_jump_speed():
return -sqrt(2 * gravity * jump_height)
func _physics_process(dt: float) -> void:
velocity.y += gravity * dt
if Enter.is_action_just_pressed("jump0"):
velocity.y = calc_jump_speed()
move_and_slide()
Nonetheless, the editor does not show up to date values once I change them: setting jump_tiles
to 1 ought to change jump_height
to 16 but it surely stays at 64 and jump_speed
is at all times 0. If I modify jump_height
to 128, my character jumps larger however no values change. The underlying values do change — my character solely jumps 1 tile. And when viewing the participant in Distant scene tab, the values all replace. However once I save the file, it shops the values seen within the Native inspector and provided that they’re modified:
[node name="Node2D" type="CharacterBody2D" parent="."]
place = Vector2(-71, 376.054)
collision_mask = 15
script = ExtResource("10_ob28b")
jump_height = 128.0
jump_tiles = 1.0
If I restart the editor, it makes use of my jump_tiles
worth and never jump_height
. It appears that evidently the values are utilized within the order they seem in script and loading jump_tiles
from the tscn executes the setter which overrides the jump_height
worth from the tscn.
I can add @software
to the highest of the script after which the values change, however then my character is troublesome to work with: they fall on account of gravity and stroll away from their spawn level within the editor scene whereas I am testing.
The Operating code within the editor docs say you should use not Engine.is_editor_hint()
to skip any code that should not run in editor (like making use of gravity), but in addition has an enormous pink warning about the way you would possibly crash the editor.
So how can I add derived inspector values with out making my entire script affected by @software
?