Dynamic asset loading (jme gradle project)

Hi

I have two models, say character1 and character2 i generated jar file for each one which contains .j3o file of model. I created them by making two subproject in my main gradle project.

...    
dependencies {
        ...    
        runtime project(':character1')
        runtime project(':character2')
    }    
    project(":character1") {
            apply plugin: "java"
            buildDir = rootProject.file("build/character1")

            // SourceSet's Configuration
            sourceSets {
                main{        
                    resources {
                        srcDir '.'
                    }
                }
            }
            
        }

        project(":character2") {
            apply plugin: "java"
            buildDir = rootProject.file("build/character2")

            // SourceSet's Configuration
            sourceSets {
                main{        
                    resources {
                        srcDir '.'
                    }
                }
            }
            
        }

Now suppose these are two new models i released them as an update to clients. So these models are not exist in my clients version yet.
I want clients be able to use these new models in their game by just downloading them from server and adding them inside lib folder of their game dynamically without needing to rebuild client code.
How can i achieve this ? Can we register them dynamically using assetManager.registerLocator ?

You are trying to solve one tiny problem at a time instead of tackling the bigger picture.

And are you trying to support mods? Or just dynamic updates?

Supporting mods is a much bigger topic… and yeah, you’ll have to do a bunch of funky gymnastics to dynamically register classpath locators for the JARs and stuff.

Just dynamic updates.

If you just want to load assets into your game from more locations than just the default assets.jar, then registering asset locators will work.

Edit: I should probably be a little more detailed, so here’s what I did in one of my projects. I wanted to load and compile a bunch of Groovy scripts at runtime from a folder inside the project’s installation directory. I wound up using the AssetManager to do this, and all it required was registering a FileLocator with the root path set to my script folder and creating my own AssetLoader to load and compile the Groovy scripts. The AssetLocator/AssetLoader pattern is quite powerful and you can get some pretty advanced functionality without doing a lot of extra work (i.e., loading assets from the internet - see the TestUrlLoading demo).

But if you built your project to run locally with those separate projects then those jars are already in the classpath. We don’t know how you actually deploy your application but presumably it’s expanded somehow and those jars are on disk.

Then your next question will be “How do I replace those jars when they change?”

…then we’ll be back to getdown and you start all over with new questions. :slight_smile:

I could setup my app with Getdown thanks to @david_bernard_31’s getdown gradle plugin . :grinning:

Paul and David thanks so much for your helps.

tutorials :