Properly removing assets

Software: Away3D 4.x

Avatar
oladitan, Member
Posted: 29 September 2014 04:08 PM   Total Posts: 71

Hi. Is there a way to properly delete assets and their materials.

In my game I need to create a new material for each enemy. I change the transparency so I give each enemy a new material that is identical to the cloned one.

If I make the texture of the enemy smaller in photoshop I can spawn more of them before the game crashes.

If I make the texture larger I can spawn way less before the game crashes.

If the materials were being properly removed. It would not matter how large the texture was.

I have tried

mesh.material.dispose();
mesh.disposeAsset();
mesh.dispose();
scene.removeChild(mesh); 

none of these seem to solve the issue.

Thanks.

   

Avatar
mrpinc, Sr. Member
Posted: 29 September 2014 04:57 PM   Total Posts: 119   [ # 1 ]

oladtian,  you should be able to create new materials that share the base texture.  There should be no need to dispose of the texture just because you want to create a new material.  You can have multiple objects with different materials (that look different) yet they share the same texture.

Also if you need a lot of different materials you should think about object pooling your materials and changing their properties every time you need them rather than instatiating a new one each time.

   

Avatar
oladitan, Member
Posted: 29 September 2014 10:19 PM   Total Posts: 71   [ # 2 ]
mrpinc - 29 September 2014 04:57 PM

oladtian,  you should be able to create new materials that share the base texture.  There should be no need to dispose of the texture just because you want to create a new material.  You can have multiple objects with different materials (that look different) yet they share the same texture.

Also if you need a lot of different materials you should think about object pooling your materials and changing their properties every time you need them rather than instatiating a new one each time.

Hi mrpinc. All the materials are made from 1 single jpeg image. When the meshes are cloned I assigned a new texture material for each one. Object Pooling is a good idea for what I am trying to accomplish now but may not work if I had a more complex scene with more enemies showing at once. RIght now there are at most 10 enemies in the scene at once. Are new materials stored in memory or something. I am using ‘Cast’ to create the texture materials. If I could find a way to free the engines resources completely of materials as they are removed from the scene I think the issue may be resolved.

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X