Skip to content

feat: add SoftReference support for CustomRoom in DungeonManager#473

Merged
MSchmoecker merged 1 commit into
Valheim-Modding:devfrom
jneb802:feat/dungeon-softreference
Apr 26, 2026
Merged

feat: add SoftReference support for CustomRoom in DungeonManager#473
MSchmoecker merged 1 commit into
Valheim-Modding:devfrom
jneb802:feat/dungeon-softreference

Conversation

@jneb802
Copy link
Copy Markdown
Contributor

@jneb802 jneb802 commented Apr 22, 2026

Summary

Adds a new CustomRoom(SoftReference<GameObject>, bool, RoomConfig) constructor so mods can register custom dungeon rooms that live in soft-reference bundles, mirroring the existing soft-ref flow for CustomLocation.

Changes

JotunnLib/Entities/CustomRoom.cs

  • New ctor CustomRoom(SoftReference<GameObject>, bool, RoomConfig).
  • Validates softReferencePrefab.IsValid; logs and bails if invalid.
  • Registers a ResolveMocksOnLoad callback parented to DungeonManager.DungeonRoomContainer.transform.
  • Populates RoomData with m_prefab = softReferencePrefab, m_loadedRoom = null, m_enabled = roomConfig.Enabled ?? true, m_theme = GetRoomTheme(ThemeName).
  • Sets a new SoftReference flag on the custom room so downstream code can branch on it.

JotunnLib/Managers/DungeonManager.cs

  • DungeonRoomContainer promoted from private to internal so the new ctor can parent the resolved asset.
  • AddCustomRoom skips Prefab.SetParent / SetActive(true) for soft-ref rooms (no prefab yet).
  • OnDungeonDBStarted skips Prefab.FixReferences(true) for soft-ref rooms — mocks are resolved later by MockResolutionContext.InstantiateAndResolveAsset when the asset actually loads.
  • GenerateHashes hashes room.Name instead of room.Prefab.name so soft-ref rooms (Prefab still null) still register.
  • OnDungeonGeneratorSetupAvailableRooms filter switched from r.Room.m_enabled to r.RoomData.m_enabled to avoid touching the lazy-loaded Room component.

- New CustomRoom(SoftReference<GameObject>, bool, RoomConfig) ctor defers
  prefab loading until DungeonGenerator requests the room, mirroring the
  SoftReference flow already used by CustomLocation.
- DungeonManager skips Prefab parenting, activation, and FixReferences for
  SoftReference rooms since the prefab is not yet loaded at registration.
- GenerateHashes now hashes room.Name instead of room.Prefab.name so
  SoftReference rooms (no loaded Prefab) still register.
- Available-room filtering uses RoomData.m_enabled instead of Room.m_enabled
  to avoid touching the lazy-loaded Room component.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@jneb802 jneb802 marked this pull request as ready for review April 24, 2026 22:52
@jneb802 jneb802 force-pushed the feat/dungeon-softreference branch from 69fa20e to 4581549 Compare April 24, 2026 23:00
@MSchmoecker MSchmoecker merged commit 7984cc8 into Valheim-Modding:dev Apr 26, 2026
2 checks 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