diff --git a/jme3-core/src/main/java/com/jme3/scene/Spatial.java b/jme3-core/src/main/java/com/jme3/scene/Spatial.java index d912b34b3..8561648b0 100644 --- a/jme3-core/src/main/java/com/jme3/scene/Spatial.java +++ b/jme3-core/src/main/java/com/jme3/scene/Spatial.java @@ -1524,19 +1524,22 @@ public abstract class Spatial implements Savable, Cloneable, Collidable, Cloneab } public void setUserData(String key, Object data) { - if (userData == null) { - userData = new HashMap(); - } - - if(data == null){ - userData.remove(key); - if(userData.isEmpty()) { - userData = null; + if (data == null) { + if (userData != null) { + userData.remove(key); + if(userData.isEmpty()) { + userData = null; + } } - }else if (data instanceof Savable) { - userData.put(key, (Savable) data); } else { - userData.put(key, new UserData(UserData.getObjectType(data), data)); + if (userData == null) { + userData = new HashMap(); + } + if (data instanceof Savable) { + userData.put(key, (Savable) data); + } else { + userData.put(key, new UserData(UserData.getObjectType(data), data)); + } } }