Singleton App Class, Control and Scene Composer

I am trying to figure out the best/correct way of Giving my control access to AssetManager and RootNode.

I have a spawner.j3o object which is a imported blender cube.
I have a platform.j3o object which is a imported blender rectangle.

I have a spawner control which extends Abstract Class. Its job is to wait for 2 sec and then spawn the platform.
It also moves the spawner as the camera moves.

public class SpawnerControl extends AbstractControl {

private  float speedOfSpawn = 2f;
private  float lastSpawn = 0f;
private boolean spawn = false;
private  Vector3f offset = new Vector3f();

protected void controlUpdate(float tpf) {
    if (lastSpawn > speedOfSpawn){
        lastSpawn = 0f;           
    }else {
        lastSpawn+= tpf;            

protected void controlRender(RenderManager rm, ViewPort vp) {

private void spawnPlatform(){   
    System.out.println("spawnPlatform " + System.currentTimeMillis());
    AssetManager assetManager = App.getInstance().getAssetManager();
    Spatial teapot = assetManager.loadModel("Models/platform.j3o");      

public float getSpeedOfSpawn() {
    return speedOfSpawn;

public void setSpeedOfSpawn(float speedOfSpawn) {
    this.speedOfSpawn = speedOfSpawn;

public Control cloneForSpatial(Spatial spatial) {
    SpawnerControl control = new SpawnerControl();
    offset = App.getInstance().getCamera().getLocation().subtract(spatial.getWorldTranslation());
    System.out.println("offset " + offset);
    return control;

I have a App class that extends SimpleApplication and has a Singleton getInstance() static Method.
It also moves the camera

private static App instance = null;

public static App getInstance(){
    if(instance == null){
        instance = new App();
    return instance;

public void simpleUpdate(float tpf) {
    cam.setLocation(cam.getLocation().add(new Vector3f(camSpeed,0,0)));

I have a Main class that creates a instance of App by
App app = App.getInstance();

The issue is I am using App.getInstance() in the control if I add the SpawnerControl to the Spatial on the SDK Scene Composer and save it will no longer be able to open in the Scene composer. I am assuming because the Scene Composer has no reference to App.getInstance()…

Can anyone tell me how to work around this or is using a Singleton a bad Idea if using Scene Composer? What is the best way to get to the AssetManager and RootNode inside a Control if I am going to use the Scene Composer.


You should probably use an AppState as a “Spawner”. A Control is related to a Spatial. At least you could use an AppState to supply the links to the Control (at runtime) instead of supplying it via the constructor.