Caching every reference in a single file

Hi, recently I’ve reasoned about the idea of caching every single reference of the scene (gameobjects, components, transforms) in a single public “cache” file. The advantages would be:

  1. simple access of any reference from any script;
  2. no overhead (as much little it could be);
  3. avoid any mistake in referencing (ie: misspelled tag or component).

I could even write an editor script to automatically create this cache file.

Do you thing this is a good approach? Is there some other different good practice that I just don’t know?

Hi there I think your idea is not bad but I think it’s have something you should consider beside the advantages.

  1. If you cache all reference of the scene, you will have to control the release of memory yourself. For example if you destroy an object inside scene at run time, if you not remove it from cache, it will stay there forever. If that object still have referenced, GC or Unity memory manager will not touch that object (I’m not sure about this).
  2. You will have to rebuild your file for every little change inside your scene. (of course you can make it generate automatically by some editor script) The more process you have the more easy error you get, and if you working in a team I think it’s will be trouble sometimes.

And beside the advantage you listed up, can you show some disadvantages of the solution above?
Since I still fresh with Unity so if I have miss understood anything, please point me. Thanks and Cheers :slight_smile: