Skip to content

Update MapInstance to support scene maps#38

Closed
zonical wants to merge 1 commit intoFacepunch:masterfrom
zonical:mapinstance-scenemaps
Closed

Update MapInstance to support scene maps#38
zonical wants to merge 1 commit intoFacepunch:masterfrom
zonical:mapinstance-scenemaps

Conversation

@zonical
Copy link
Copy Markdown

@zonical zonical commented Nov 27, 2025

This PR is a band-aid solution that allows the loading of scene maps via the MapInstance component. The changes are very minimal, and my map Street loads perfectly fine.

💬 MapInstance sucks, we should get rid of it!

Yes, yes, yes, I've heard that MapInstance is the devil and that Facepunch wants to get rid of it at some point. I'm all for that, but there's no established timeline for when scene maps will be loadable and usable in-game/in-editor.

💬 Why create your own component to load the scenes?

I have tried this, but I've run into a bug where a SceneWorld created from a SceneMap class doesn't get removed properly. This bug can be prevented, but the change must be made at a lower level that normal components can't access. MapInstance appears to clean things up properly with the appropriate level of access, so that's why I've put these changes in here.

image

Example of the bug in action. This is out of the scope for this PR and should be addressed separately.

@garrynewman
Copy link
Copy Markdown
Member

I thought this already worked. Long term we do need a better solution than MapInstance, but I agree that we should be able to load scene maps through this in the meantime.

@zonical
Copy link
Copy Markdown
Author

zonical commented Nov 27, 2025

A check was deliberately added to prevent scenes from being loaded, hence the pull request. I was pleasantly surprised to find how well the MapLoader class actually handled the loading of scene maps during my initial experimentation.

Although this doesn’t fit the purpose of the pull request, it might be worth considering a plan to introduce scene maps in the editor sooner rather than later. It would be really handy if developers could load scene maps and then insert their own GameObjects on top. My game, Physbox, uses a system similar to this where breakable props and other map features such as clip brushes and barricades are manually placed on top of the Map Instance. Just some food for thought.

@garrynewman
Copy link
Copy Markdown
Member

We have a couple of things to facilitate that. We have a System Scene - which is auto added to every loaded scene. And we have GameObjectFlags.DontDestroyOnLoad - which will make GameObjects stay when the scene is changed.

@zonical
Copy link
Copy Markdown
Author

zonical commented Nov 27, 2025

System Scenes and GameObjectFlags don't provide the functionality that I'm looking for. The approach I would like to see would be similar to how Map Extensions are handled in Half-Life: Alyx. More specifically, treating scene maps as just another scene that can be loaded in the editor (the functionality is technically there since scene maps are just SceneFile resources, IIRC), but in a "read-only" state. The developer can add their own GameObjects on top to extend the original scene. I don't know if that sounds too complicated or if it's at all practical to implement.

This is already kind of possible by creating a new scene, adding a Map Instance component with a Hammer/Scene Map, and then adding your own GameObjects. This is the approach I use in Physbox (see image below).

image

This discussion is probably getting a bit out of scope for this PR. The ability to load scene maps with the Map Instance component is a good temporary measure that can be revisited later.

@garrynewman garrynewman added the triaged triaged pull-requests are replicated on the internal sbox repo label Nov 28, 2025
@sboxbot sboxbot added the accepted this pull request was accepted, hurrah! label Nov 29, 2025
@sboxbot
Copy link
Copy Markdown
Contributor

sboxbot commented Nov 29, 2025

This PR has been merged upstream.

@sboxbot sboxbot closed this Nov 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

accepted this pull request was accepted, hurrah! triaged triaged pull-requests are replicated on the internal sbox repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants