Skip to content

(WIP) Make adressables great again #1494#1500

Open
rohitkulkarni97 wants to merge 238 commits intoRE-SS3D:developfrom
rohitkulkarni97:Issues/Make-Adressables-great-again-#1494
Open

(WIP) Make adressables great again #1494#1500
rohitkulkarni97 wants to merge 238 commits intoRE-SS3D:developfrom
rohitkulkarni97:Issues/Make-Adressables-great-again-#1494

Conversation

@rohitkulkarni97
Copy link
Copy Markdown
Contributor

Summary

PR checklist

  • The game builds properly without errors.
  • No unrelated changes are present.
  • No "trash" files are committed.
  • Relevant code is documented.
  • Update the related GitBook document, or create a new one if needed.

Pictures/Videos

Testing

Networking checklist

  • Works from host in host mode.
  • Works from server in server mode.
  • Works on server in client mode.
  • Works and is syncronized across different clients.
  • Is persistent.

Changes

Related issues/PRs

…eters in asset creation methods, and removing DatabaseAsset.cs usage.
….Get method instead of DatabaseAsset's Prefab property, Create, Get<T>() & CreateAs<T>(...) functions, and different implicit operators.
…Creator and DatabaseScriptWriter for consistency in asset management workflow.
…, and Item to use Assets.Get method for improved consistency and clarity
…to use Assets.Get method for improved consistency
…and other places to streamline asset retrieval
…tepCraftable, and Item to simplify usage of Assets.Get method
…nce to streamline addressable asset handling and improve code clarity
…nstructionHologramManager to utilize WorldObjectAssetReference for improved asset retrieval
…bjectsSO prefabs to enhance asset management
…eferences throughout the codebase for consistency
…AssetReference, and implement IEqualityComparer for improved comparison
…lementation and simplifying equality and hash code methods
…eters in asset creation methods, and removing DatabaseAsset.cs usage.
….Get method instead of DatabaseAsset's Prefab property, Create, Get<T>() & CreateAs<T>(...) functions, and different implicit operators.
…Creator and DatabaseScriptWriter for consistency in asset management workflow.
…, and Item to use Assets.Get method for improved consistency and clarity
…to use Assets.Get method for improved consistency
…and other places to streamline asset retrieval
NetworkObjectTracker is a MonoBehaviour that carries the asset GUID so
dependency prefabs loaded implicitly by Addressables can be discovered
at runtime. The Generate() pass now stamps the tracker onto every prefab,
fixing GUID mismatches from prefab moves or copies.
When GetObject encounters a null prefab slot, it scans all loaded
NetworkObjectTracker instances to find dependency prefabs that were
loaded by Addressables but never received an OnLoaded event, and
registers them into their deterministic FishNet runtime slots.
Verify that the generator adds NetworkObjectTracker with the correct
GUID and that re-running the generator does not duplicate the component.
Remove StartAssetEditing/StopAssetEditing batching so base prefab
imports complete before variants are processed, making inherited
trackers visible to TryGetComponent. Add DisallowMultipleComponent
as a safety net against duplicate trackers.
Move OnLoaded invocation out of the awaited path so it fires exactly
once per handle regardless of how many callers await the same GUID.
The callback captures itself to unsubscribe on first invocation.
Variant prefabs that were reverted from the initial generation now
carry the tracker GUID override produced by the fixed generator.
InstanceLifetimeTracker has DisallowMultipleComponent, so a second
AddComponent call would fail and the subsequent Initialize would throw.
Use TryGetComponent first, and re-initialize if the tracker's key is
stale (e.g. from prefab variants inheriting the base's tracker).
Scanning in GetObject was too late — the server reads PrefabId from a
spawned instance before the client ever calls GetObject, so dependency
prefabs that weren't registered sent garbage IDs over the network.

Scanning on HandleAssetLoaded ensures every loaded prefab (root or
implicit addressable dependency) has its FishNet PrefabId set before
any spawn reads it. A per-tracker Initialized flag skips already
processed instances, and the scan no longer short-circuits on slot
occupancy so multiple in-memory copies of the same prefab (e.g. a
direct scene reference plus the addressable-loaded copy) each get
their PrefabId set.
Scenes can carry directly referenced NetworkObject prefabs (including
addressable ones resolved via serialized references) that never fire
HandleAssetLoaded. Scan once in OnEnable to cover the currently loaded
scene and subscribe to SceneManager.sceneLoaded for future scenes.

Add TryRecoverSlot so GetObject can re-point an empty slot at any
surviving in-memory copy of the prefab — covers the case where a
transitive addressable dependency was released without firing
HandleAssetUnloaded, but another copy (e.g. scene reference) is still
alive. Moves the tracker Initialized flag into InitializePrefab so every
registration path keeps FishNet and tracker state in sync.
…leObject

Converts the IAssetDatabase interface into an abstract ScriptableObject base
class so database instances can be assigned to serialized fields in the
inspector. DatabaseID moves to the base, and AssetGuids is exposed as an
abstract IReadOnlyCollection<string> property so backends can back it with
their own storage (List, HashSet, Dictionary.Keys, etc.) without
double-serializing the GUID set.

- Rename IAssetDatabase.cs to AssetDatabase.cs (preserves the meta GUID).
- AddressablesDatabase inherits from AssetDatabase and overrides AssetGuids
  and ResolveKey.
- Move the code-gen helper (GenerateDatabaseCode, path constants) to an
  AssetDatabase.Editor.cs partial so every database type inherits it.
- Alias UnityEditor.AssetDatabase as UnityAssetDatabase in files that now
  see the new class in scope, to resolve the name collision.
- Widen AssetSubSystem._databasesById and GetDatabase to AssetDatabase, and
  materialize AssetGuids in CraftingSubSystem since IReadOnlyCollection has
  no indexer.
… backend factory

Catalogs now own their databases (serialized List<AssetDatabase>) and produce
their own backend via an abstract factory method, so AssetSubSystem no longer
hardcodes which backend or catalog to instantiate. Adding a new backend means
adding a catalog + backend pair, with no AssetSubSystem changes.

- Rename IAssetCatalog.cs to AssetCatalog.cs (preserves the meta GUID).
- AddressablesCatalog becomes a ScriptableObject with a [CreateAssetMenu],
  overriding BackendType and CreateBackend. Runtime Initialize/Reset are
  gone — the serialized _databases list and the base's Has/ResolveKey
  implementations take their place.
- AssetDatabaseSettings gains List<AssetCatalog> IncludedCatalogs alongside
  the existing IncludedAssetDatabases (which still drives code-gen).
- AssetSubSystem.InitializeInternalAsync discovers catalogs from settings,
  calls CreateBackend once per distinct BackendType, and registers each
  catalog's databases in a single pass.
Unity re-saved all eight databases after the AssetDatabase refactor: the
removed DatabaseName field is dropped, and the AssetGuids public field is
renamed to the private backing field _assetGuids. GUID lists are preserved.
…ings

Wires the new catalog system at runtime: a single AddressablesCatalog asset
groups the eight existing AddressablesDatabase assets and is registered in
AssetDatabaseSettings.IncludedCatalogs, which AssetSubSystem now reads on
init. Confirmed in Play mode with "7 asset databases initialized".
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant