Skip to content

Add compatibility with SoftReferenceableAssets for customLocations#455

Merged
MSchmoecker merged 30 commits into
Valheim-Modding:devfrom
jneb802:softRef_locations
Jul 12, 2025
Merged

Add compatibility with SoftReferenceableAssets for customLocations#455
MSchmoecker merged 30 commits into
Valheim-Modding:devfrom
jneb802:softRef_locations

Conversation

@jneb802
Copy link
Copy Markdown
Contributor

@jneb802 jneb802 commented May 4, 2025

The goal of this PR is to change where a Location's prefab is stored.

The current implementation of Jotunn.ZoneManager stores all CustomLocation prefabs in a LocationContainer GameObject, which is held in the DontDestroyOnLoaded scene. This approach causes CustomLocations prefabs to always be held in the client's memory and therefore leads to very high RAM usage when large numbers of CustomLocations are added. This PR transitions CustomLocation prefabs to use the new vanilla SoftReferenceableAsset system, which allows prefabs to be loaded from AssetBundles on disk only when they are needed.

This PR solves the above problem by making changes to three files in Jotunn. Mod developers will still need to follow additional steps to make their assetBundles available to the SoftReferenceableAssets system. The steps will be outlined in a future documentation page.

CustomLocation.cs

  • A new bool softReference field. This field is used in ZoneManager Harmony patches to check if mocks should be resolved for the customLocation.
  • A new CustomLocation constructor which gets the CustomLocations SoftRef prefab.

PrefabManager.cs

  • Add a new check if prefab name is has "JVLmock_". SoftReference mocks are resolved at a later point that before therefore many of the prefabs with the "JVLmock_" prefix were being automatically added to PrefabManager.

ZoneManager.cs

  • Add a Harmony Prefix to ZoneSystem.SpawnLocation(). This prefix is where we now resolve mocks for softReference locations.
  • Add a Harmony PostFix to ZoneSystemSpawnLocation() to add an additional Release(). We added an additional Load() call in our prefix so we must also include an additional Release().
  • Add checks if customLocation use softReference to skip existing logic
  • Add checks if prefab starts with "JVLmock_" to skip adding to PrefabManager

Comment thread JotunnLib/Entities/CustomLocation.cs Outdated
Comment thread JotunnLib/Managers/ZoneManager.cs Outdated
jneb802 and others added 27 commits June 15, 2025 07:13
@MSchmoecker MSchmoecker merged commit c1b86be into Valheim-Modding:dev Jul 12, 2025
1 check passed
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.

2 participants