No clearUserdata?

for (String key: new ArrayList(spatial.getUserDataKeys()))
            spatial.setUserData(key, null);

simple as that

I totaly agree, but one should have the possibility to assign user data to scenegraph elements

groovy :smile:

this one even better :

 for (String key: new ArrayList<String>(spatial.getUserDataKeys()))
            spatial.setUserData(key, null);

yes maybe I should add a custom prefix for the blender object custom properties
so I dont whipe internal JME stuffs
thanks :stuck_out_tongue_winking_eye:

in the case one dont use setUserData, what in the case you got thousands of objects, you only need to check what real-non-jme-programmer-internal data is associated with a particular spacial ???

I donā€™t even know why you would need to do this.

Is it really a use case that code randomly is adding stuff to your spatials and you donā€™t know about? Do you have like a team of 50 guys just setting someSpatial.setUserData(ā€œSomeCrapWeDonā€™tReallyNeedā€, 1)?

Itā€™s a bit mind boggling that itā€™s possible to be so completely unaware of what one part of your app is doing that you need to whack it all with a nuke every now and then.

ā€œJME shouldnā€™t be setting stuff to user dataā€¦ but itā€™s totally cool if the blender loader does itā€¦ā€ uhhhā€¦

??? what if you click one a spatial, could be anything, any king of object, your game logic has to figure what kind of object
and you dont use getName cos defining behaviour from an object name is dodgy, what if the name changes
personaly I dont like that approachā€¦

first I used Control class for my AI/Game logic, then I realized I should implement my own Controller classes to do that instead (you pointed that to me actually in another thread)

so I obviously need to have some link between some spatials in the scenegraph and some of my Controller instances
cos Spatial and Control classes are not supposed to hold game items/characters data/stats

thatā€™s allā€¦

and I never said anything like ā€œJME shouldnā€™t be setting stuff to user dataā€¦ but itā€™s totally cool if the blender loader does itā€¦ā€ā€¦ I asked why the Blender importer did thatā€¦cos they are user (not JME) defined propertiesā€¦nothing internal
so following your logic, it shouldā€™nt do that

The point he makes is that your code should know what it sets so it should also know what it has to remove. If we followed your logic then there also shouldnā€™t be anything like AnimControls or stuff like that because ā€œControls are for usersā€ and ā€œusers should be able to remove all Controls from a Spatial without having to fear that they remove a Control added by jMEā€ā€¦

ok then Iā€™ll use setUserData with my own prefix, and that solves it

jME3 uses UserData internally for certain fields which are uncommon or which make sense in only specific scenarios. All jME3 UserData fields are prefixed with the string "Jme". To avoid collisions, you should not start your fields with the string "Jme".

1 Like

tadaaaaa, finaly
thanks mate

Thats only the case for two of the UserData entries that the engine uses.

ā€¦this part I donā€™t understand. My contention all along is that JME might put stuff in there. Of course you can also put stuff in thereā€¦ I never said otherwise.

Just that itā€™s bad practice to want to clear everythingā€¦ because itā€™s incredibly reckless and a sign that your code is hopelessly seat-of-the-pants.

sorry I just got you worng
I agree clearing blindly that list is really not a good idea if jme stores stuff in there