Editor Plugin cant save/edit resource

Godot Version

4.6

Question

making an editor plugin to help make items/tiles easier for my game, i store all the them in a custom resoruce thats just an array, no matter what i do i cant get the resource to update, ive gone as far as deleting it and remaking it with the code below but it still holds all the old values, like the chached version is taking over.my script shows no errors. in fact it tells me yup saving 22 items but the DB forever stays at 20 , i have restarted the editor and my pc many times, very very rarley it will work and ill see the new items, but not consistantly please help. this was supposed to save me time but ive spent 2 days on this so far, trying all sorts

func _on_rebuild_db_pressed() -> void:
	# 1) Scan disk for items (do NOT rely on DB)
	var files := _scan_tres_files(ITEMS_DIR)
	if files.is_empty():
		_set_status("ERROR: No .tres files found in: %s" % ITEMS_DIR)
		return

	if not _ensure_itemdata_script():
		return

	var typed: Array[Resource] = [] # keep as Resource to avoid type issues in tool scripts
	var ok_count := 0
	var bad_count := 0

	for p in files:
		var res := ResourceLoader.load(p, "", ResourceLoader.CACHE_MODE_IGNORE)
		if res == null:
			bad_count += 1
			continue

		if _get_script_path_of(res) != ITEMDATA_SCRIPT_PATH:
			bad_count += 1
			continue

		# Validate minimal fields
		var id_v = res.get("id")
		if id_v == null or StringName(id_v) == &"":
			bad_count += 1
			continue

		ok_count += 1
		typed.append(res)

	if typed.is_empty():
		_set_status("ERROR: Rebuild cancelled. 0 valid ItemData found in: %s" % ITEMS_DIR)
		return

	# 2) Sort deterministically by id (stable output)
	typed.sort_custom(func(a: Resource, b: Resource) -> bool:
		var aid := String(a.get("id"))
		var bid := String(b.get("id"))
		return aid.naturalnocasecmp_to(bid) < 0
	)

	# 3) Back up existing DB
	if ResourceLoader.exists(ITEM_DB_PATH):
		var abs_src := ProjectSettings.globalize_path(ITEM_DB_PATH)
		var abs_bak := ProjectSettings.globalize_path(ITEM_DB_PATH + ".bak")
		if FileAccess.file_exists(abs_bak):
			DirAccess.remove_absolute(abs_bak)
		var rerr := DirAccess.copy_absolute(abs_src, abs_bak)
		if rerr != OK:
			_set_status("ERROR: Failed to backup Item DB (err=%d): %s" % [rerr, ITEM_DB_PATH + ".bak"])
			return

	# 4) Create a brand new DB resource and save it
	# Assumes: class_name ItemDatabaseResource, export var items: Array[ItemData]
	var new_db := ItemDatabaseResource.new()
	new_db.set("items", typed)
	new_db.emit_changed()

	_ensure_res_dir(ITEM_DB_PATH.get_base_dir())

	var err := ResourceSaver.save(new_db, ITEM_DB_PATH)
	if err != OK:
		_set_status("ERROR: Failed to write Item DB (err=%d): %s" % [err, ITEM_DB_PATH])
		return

	# 5) Refresh editor filesystem (optional but helps)
	if Engine.is_editor_hint() and _editor_if != null:
		_editor_if.get_resource_filesystem().scan()

	# 6) HARD VERIFY: reload what we just wrote (REPLACE bypasses cache)
	var reloaded := ResourceLoader.load(ITEM_DB_PATH, "", ResourceLoader.CACHE_MODE_REPLACE)
	if reloaded == null:
		_set_status("VERIFY FAILED: could not reload Item DB after save.")
		return

	var arr_any = reloaded.get("items")
	var count := 0
	if arr_any is Array:
		count = (arr_any as Array).size()

	print("VERIFY Item DB reload items_count=", count)
	if arr_any is Array:
		var a := arr_any as Array
		for i in range(min(5, a.size())):
			var it = a[i]
			if it is Resource:
				print("  [", i, "] id=", StringName((it as Resource).get("id")), " path=", (it as Resource).resource_path)

	# 7) Update the dock list from disk too
	_refresh_items_list()
	_set_status("Rebuilt Item DB from disk with %d items. (skipped %d)" % [ok_count, bad_count])

then the resource is just a simple array of resoruces @tool
@tool
extends Resource
class_name ItemDatabaseResource

@export var items: Array[ItemData] =

Double check this block.
The set function will do nothing if items doesn’t exist. It does so that is not a problem.
But it will also do nothing if the types mismatch.
So if typed doesn’t evaluate to an Array[ItemData] nothing will be set.
Is there a reason why you can’t just access that property directly? (Maybe its something that can’t be done in tool mode?)
If this is the problem, you would get an error message instead of the do-nothing.
new_db.items = typed

yeah it was silently failing, managed to get it by doing everything, building a fresh resource, asigning it directly then doing the Take over Path thing, saving it then forcing cache mode replace, func _rebuild_tile_db_pressed() → bool:

Re-scan tiles from disk

_refresh_tiles_list()

if _tiles.is_empty():
	_set_status("ERROR: Rebuild cancelled. 0 valid TileVisual3D found in: %s" % TILES_DIR)
	return false

# Build a STRICT typed array
var typed: Array[TileVisual3D] = []
for r in _tiles:
	if r is TileVisual3D:
		var tv := r as TileVisual3D
		if tv.key != &"":
			typed.append(tv)

# Debug: confirm we really have Array[TileVisual3D]
print("RebuildTileDB: typed_count=", typed.size(), " typed_is_Array_TileVisual3D=", (typed is Array[TileVisual3D]))

if typed.is_empty():
	_set_status("ERROR: 0 typed tiles after filtering (check tile scripts / keys).")
	return false

# Create a brand new DB resource and assign property directly (NOT set())
var new_db := TileVisualDBData.new()
new_db.tiles = typed
new_db.emit_changed()

# replace cached resource at this path in editor
new_db.take_over_path(TILE_DB_PATH)

var err := ResourceSaver.save(new_db, TILE_DB_PATH)
print("TileDB save err=", err)
if err != OK:
	_set_status("ERROR: Failed to save tile DB (err=%d): %s" % [err, TILE_DB_PATH])
	return false

# Force reload (replaces cache) so editor/inspector sees the new instance
var reloaded := ResourceLoader.load(TILE_DB_PATH, "", ResourceLoader.CACHE_MODE_REPLACE)
if reloaded == null:
	_set_status("ERROR: Saved DB but failed to reload: %s" % TILE_DB_PATH)
	return false

# Verify contents
var arr_any = reloaded.get("tiles")
var c := (arr_any as Array).size() if (arr_any is Array) else -1
print("VERIFY TileDB tiles_count=", c)
if arr_any is Array:
	for i in range(min(5, c)):
		var t = (arr_any as Array)[i]
		if t is TileVisual3D:
			print("  [", i, "] key=", (t as TileVisual3D).key, " path=", (t as TileVisual3D).resource_path)
		else:
			print("  [", i, "] unexpected type=", typeof(t))

if Engine.is_editor_hint() and _editor_if != null:
	_editor_if.get_resource_filesystem().scan()

_set_status("Rebuilt Tile DB with %d tiles." % typed.size())
return true