@@ -266,15 +266,6 @@ pc.extend(pc, function () {
266266 _onMaterialAsset : function ( asset ) {
267267 var assets = this . system . app . assets ;
268268
269- // unsubscribe
270- if ( this . data . materialAsset !== asset . id ) {
271- if ( this . data . materialAsset )
272- this . _onMaterialAssetRemove ( this . data . materialAsset ) ;
273-
274- assets . on ( 'load:' + asset . id , this . _onMaterialAsset , this ) ;
275- assets . once ( 'remove:' + asset . id , this . _onMaterialAssetRemove , this ) ;
276- }
277-
278269 if ( asset . resource ) {
279270 this . material = asset . resource ;
280271 } else {
@@ -290,19 +281,27 @@ pc.extend(pc, function () {
290281 var assets = this . system . app . assets ;
291282 var self = this ;
292283
284+ // unsubscribe
285+ if ( this . data . materialAsset !== id ) {
286+ if ( this . data . materialAsset )
287+ this . _onMaterialAssetRemove ( this . data . materialAsset ) ;
288+
289+ if ( id ) {
290+ assets . on ( 'load:' + id , this . _onMaterialAsset , this ) ;
291+ assets . once ( 'remove:' + id , this . _onMaterialAssetRemove , this ) ;
292+ }
293+ }
294+
293295 // try to load the material asset
294296 if ( id !== undefined && id !== null ) {
295297 var asset = assets . get ( id ) ;
296298 if ( asset )
297299 this . _onMaterialAsset ( asset ) ;
298300
299301 // subscribe for adds
300- assets . on ( 'add:' + id , this . _onMaterialAsset , this ) ;
302+ assets . once ( 'add:' + id , this . _onMaterialAsset , this ) ;
301303 } else if ( id === null ) {
302304 self . material = pc . ModelHandler . DEFAULT_MATERIAL ;
303-
304- if ( this . data . materialAsset )
305- this . _onMaterialAssetRemove ( this . data . materialAsset ) ;
306305 }
307306
308307 var valueOld = this . data . materialAsset ;
0 commit comments