Repository navigation
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This has taken me a while to get around to doing but I finally did it. I've revised the changes to handling TerrainOp registration to no longer rely on ZNetScene and instead a postfix patch runs anytime that ObjectDB.UpdateRegisters is called. This has the added benefit of catching any possible removals of registered custom TerrianOps that occur during gameplay, which did seem to occur intermittently during gameplay.
Currently any prefab or CustomPrefab that is added via a call to AddPrefab is checked for a TerrainOp component and added to the cached map of custom TerrainOp instances that need to registered in ObjectDB. From my understanding, this should catch any custom items that are added and have TerrainOp components as well as ItemManager does call AddPrefab when adding and registering custom items.
I also included a TerrainOp registration check for GameObjects in RegisterToZNetScene though, as that method is public and I know some mods call it directly to add prefabs without ever calling AddPrefab. The check in RegisterToZNetScene first checks if the name hash is already in the cached map of custom TerrainOps before attempting to get a TerrainOp component to avoid doubling up on GetComponent calls for prefabs added via the AddPrefab method. If the GameObject does has a TerrainOp component and is not already tracked, it does then immediately register the new TerrainOp and add to the cached map to ensure it remains registered.
I did not include a safety check ObjectDB.instance is not null when registering a TerrainOp as the registration method is private and only called as a postfix to ObjectDB.UpdateRegisters and via RegisterToZNetScene so it would be an unnecessary defensive check that would be repeated for every single TerrainOp added.
From my testing AdvancedTerrainModifiers, applying a postfix patch to ObjectDB.UpdateRegisters to re-register custom TerrainOps does completely solve the issue of intermittently unregistering them during gameplay as I have had not gotten any more bug reports regarding that in the month since I added a similar patch to AdvancedTerrainModifiers.
I have not investigated how these changes function when adding things via the AssetManager but given that there were no reported issues with TerrainOp components included in custom assets once the previous approach of registering TerrrainOps in RegisterToZNetScene, I believe there should be no issues introduced by these changes as they preserve that behavior.
One thing I did not add but have considered is whether there should be hookable event that occurs upon registration of the TerrianOps? I'd appreciate any input on that and welcome any other feedback regarding the proposed changes in this PR.