Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better Mod Support #2228

Open
jhimes144 opened this issue Apr 15, 2024 · 0 comments
Open

Better Mod Support #2228

jhimes144 opened this issue Apr 15, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@jhimes144
Copy link

jhimes144 commented Apr 15, 2024

Is your feature request related to a problem? Please describe.
Although its completely undocumented, Stride is very close to having a robust real-time solution to loading external asset databases in real-time within a running game instance. Now, I've looked at the inner workings of the ContentManager, file providers, and database classses and what is happening in there is not straight forward, so I may be missing something. Afterall, I have no idea how the editor is able to load assets in real time like it does.

I've been able to place assets in a class library, force it to compile the assets to a content database via <StrideIsExecutable>true</StrideIsExecutable>, and load the assets into a ContentManager with the following code

    ContentManager buildContentManager(string modDirectory)
    {
        var contentDbPath = Path.Combine(modDirectory, _contentDbPath); // contentDbPath is data/db
        
        // stride needs something for the root path in order for everything to work.
        var id = "/" + Guid.NewGuid();
        
        // file provider does some special self registration
        _ = new FileSystemProvider(id, contentDbPath);
        
        var objectDb = new ObjectDatabase(id, "index", "/local/db");
        var databaseProvider = new DatabaseFileProvider(objectDb);
        var service = new DatabaseFileProviderService(databaseProvider);
        var contentManager = new ContentManager(service);

        return contentManager;
    }

The problem I think I'm running into however, is that the game's content manager and its database provider are coupled tightly with other areas of game code including render logic. So although I'm able to load, say a model from the mod's content manager successfully, placing it in the scene does not have it rendered. Presumably, this is because some other code is looking for that model in the game's content manager.

Describe the solution you'd like
Please note I'm not too familiar with Stride's codebase, so I may be spitballing bad ideas here.

I think the easiest solution would be to create "Patching" methods to the game's content manager so that I can place content within but have them only exist in memory. Likewise, an unpatch method to remove the asset.

Another solution would be to decouple other areas of code to a given content manager. It smells like a codesmell that somehow somewhere in the code a model is being referenced back to the content manager. I may be missing something, this may not even be the case.

A more proper solution is probably a richer ContentManager that can infer from multiple sources.

Finally, in any case, I think documentation on how to go about making a Stride game moddable in terms of assets would be of great value.

Describe alternatives you've considered
I have been able to get a working solution by saving assets loaded from a mod's ContentManager into the game's ContentManager at runtime. This isn't elegant however, because it clutters the game's database with mod files that would have to be cleaned up and managed later.

@jhimes144 jhimes144 added the enhancement New feature or request label Apr 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant