Assets are statics? [Solved]

Hi there!

I have a really simple question that I couldn’t find the answer: Do assets are loaded statically by jme or it loads your assets everytime you tell it to?

If it’s static, then doing [java]new Material(assetManager, “a material”);[/java] massively won’t make my game laggs a lot?

Thank you!

The assetManager caches the assets by their name, so any model, audio data or image that is loaded via the assetManager is never loaded twice, hence you can use the same assetManager.loadModel() command each time you want to display a model in the scene, the actual material data is not really relevant anyway tho.

1 Like

But… I question your use case, though. While the AssetManager will cache stuff for you it’s still not always a great idea to create a “massive” number of materials for other reasons.



Can you tell us more about why you are doing that?

It was only to know if I needed to optimize my code or not.



‘’“massive” number of materials for other reasons.’’



What if it is only audio? Could you explain more why it would not be a great idea only for materials please? :slight_smile: Also, if using the assetManger.Load() massively isn’t good, is there another way to load my assets but only once for all my variables?



Thank you!

Assets are fine. But 10,000 material instances implies that every geometry gets its own and that there are lots of them. In general, you try to minimize state transitions within OpenGL if possible and if you are loading “massive” amounts of materials (still not sure what massive is in this case) then it may be a sign that you are missing opportunities to share state.



Then again, if they are all the same j3m or j3md and you don’t really change anything about them then they are essentially free other than all of the Material instance clones that you are creating. Which is pretty small in the scheme of things.

1 Like

Actually, what I may load massively are models (but models contain material(s)). Let’s say I have 500 units that share the same model. I also want those units to have a particle emitter but different for every unit. How can I clone the model without loading the model multiple times?

If you load the model multiple times through asset manager then it is already caching and cloning it for you as needed.

1 Like

Thank you! :slight_smile: