Inconsistent Invalid index type for dictionary

Caching might not be helping as much as you think, especially for UI. At a base level the operating system will already cache files read, so re-reading will be much faster. Godot will also cache loaded resources, guaranteeing a similar much faster re-loading. Adding objects to the scene tree will take resources, usually rendering and especially 3D rendering objects are the worst offenders. If you are trying to save from instancing and destroying the same UI panel, showing/hiding would be more performant but we’re talking about a minuscule operation that only happens on occasion, if it were per-frame then it might be worth looking into optimizations.

If you continue this route anyways, it sounds like you could use any type as the key; it may be better to use a string path to the scene or script you want to instantiate and keep.