Hi forum,
I’ve created a “Scene.java” class file which will contain all my scene-related methods, but when I try to call assetManager.loadModel(); from within the Scene class I get a NullPointerException. Here is my code:
Scene.java excerpt:
[java] private Spatial sceneModel;
public void loadScene() {
//Load the scene files
sceneModel = assetManager.loadModel(“Scenes/main.scene”);
rootNode.attachChild(sceneModel);
AmbientLight al = new AmbientLight();
al.setColor(ColorRGBA.White.mult(5f));
rootNode.addLight(al);
DirectionalLight dl = new DirectionalLight();
dl.setColor(ColorRGBA.White);
dl.setDirection(new Vector3f(2.8f, -2.8f, -2.8f).normalizeLocal());
rootNode.addLight(dl);
}[/java]
And how I call this method in Main.java
[java]
public void simpleInitApp() {
Scene scene = new Scene();
scene.loadScene();
}[/java]
The NullPointerException occurs on the line where I call assetManager.
The way this works in java is very different to the way I’m used to in C++!
EDIT: I’d also like to mention that this function works perfectly alright if I put it in Main.java
Thanks in advance,
Gary
1 Like
The assetManager of the Scene class is probably never initialized…
I doubt this differs a lot from C++
just pass it to your method
[java]
public void loadScene(AssetManager assetManager) {
//Load the scene files
sceneModel = assetManager.loadModel("Scenes/main.scene");
//do your stuffs…
}
[/java]
then
[java]
public void simpleInitApp() {
Scene scene = new Scene();
scene.loadScene(assetManager);
}
[/java]