Load saved j3o files

So I basically have a model(in j3o format), that I want to load into a game and then when the game is stopped, the model is saved and loaded again. So everytime I run the program there would be one more model in the game. My problem is, I want to have the saved j3o loaded in a folder called SavedGames. However, the code below works, because everytime the game runs i see the model loaded, but there is no folder called SavedGames generated in my assets folder.
package mygame;

import com.jme3.app.SimpleApplication;
import com.jme3.asset.plugins.FileLocator;
import com.jme3.export.binary.BinaryExporter;
import com.jme3.light.DirectionalLight;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.FastMath;
import com.jme3.math.Vector3f;
import com.jme3.renderer.RenderManager;
import com.jme3.scene.Geometry;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial;
import com.jme3.scene.shape.Box;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;


  • test

  • @author normenhansen
    public class Main extends SimpleApplication {

    public static void main(String[] args) {
    //specify your settings here
    Main app = new Main();



    public void simpleInitApp() {
    //load model from save
    String userHome = System.getProperty(“user.home”);
    assetManager.registerLocator(userHome, FileLocator.class);
    Node loadedNode = (Node) assetManager.loadModel("/SavedGames/savedgame.j3o");
    }catch (com.jme3.asset.AssetNotFoundException e){}

     //display model
     Spatial mymodel = assetManager.loadModel("Models/MyModels/mymodel.j3o");
     mymodel.move(FastMath.nextRandomFloat()*2-5, FastMath.nextRandomFloat()*2-5,FastMath.nextRandomFloat()*2-5);
     DirectionalLight sun = new DirectionalLight();
     sun.setDirection((new Vector3f(-0.5f,-0.5f,-0.5f)));

    public void stop(){
    //save model
    String userHome = System.getProperty(“user.home”);
    File file = new File(userHome + “/SavedGames/” + “savedgame.j3o”);
    BinaryExporter exporter = BinaryExporter.getInstance();
    exporter.save(rootNode, file);
    }catch(IOException ex){
    Logger.getLogger(Main.class.getName()).log(Level.SEVERE, “Error: Failed to save game!”, ex);

    public void simpleUpdate(float tpf) {
    //TODO: add update code

    public void simpleRender(RenderManager rm) {
    //TODO: add render code

Well if you create the SavedGames folder in your user.home directory, why do you expect it to suddenly appear in the assets folder anyway?

1 Like

To make it appear in the Asset folder (if not moved anywhere)
[java] String assetFolder = System.getProperty(“user.dir”) + “/assets”; [/java]

Where exactly is the user.home directory? I’m doing this off a tutorial so I still need to orientate myself. I checked the game project folder and there isn’t a SavedGames folder.

1 Like

Thank you! I’ve found it and there indeed is a savedgames.j3o file.