Clear baked cache of a Curve3D

Godot Version

4.2

Question

Hi guys,
I’m working on a platformer where the player can only move along predefined paths.
In order to easily build my levels, I created a library of “tiles” made of one mesh (for visual purpose only) and its corresponding Path3D.

I coded a script that keeps track on which tile is active and moves the player along it using sample_baked_with_rotation() that looks like this in pseudocode:

current_tile.get_next_position(player, velocity)
if (current_tile.has_reached_end_of_path):
   current_tile = get_adjacent_tile(current_tile)

It’s all working great, and as a next step, I was considering doing the folllowing:

  • sample the current tile with a low bake_interval value for extra precision
  • clear the _baked_cache of the tile as soon as the player has moved away from it

My questions are:

  • Do you think it’s worth it to clear the baked_cache or Godot does it automatically?
  • If I do need to clear it, how should I do it since the _baked_cache property isn’t exposed?

Thanks for the help!

Worry about performance once you hit a performance issue.

But if you still want to “optimize” I guess you could set a big value to Curve3D.bake_interval and call Curve3D.get_baked_length() to update the baked data. You’ll need to set it back to a lower value when the player is going to enter that tile.

Thanks, setting a big value and calling Curve3D.get_baked_length() to force recompute the cache is the way I’m doing it right now.
Out of curiosity, if for some reason (for this use case or another) I want to access a variable or method from an engine class that is not exposed, what’s the best way to do it ? Patch the engine ?

If the variable isn’t exposed to the scripting side in any way then, yes, you’ll need to modify the engine source code and compile your own build.