@@ -22,6 +22,7 @@ import { useArrayState } from '../../../hooks/useArrayState'
2222import { analytics , Event } from '../../../lib/logic/analytics'
2323import { EditorComponentsTypes } from '../../../lib/sdk/components'
2424import { getAssetByModel } from '../../../lib/logic/catalog'
25+ import { updateGltfForEntity } from '../../../lib/babylon/decentraland/sdkComponents/gltf-container'
2526
2627import { Block } from '../../Block'
2728import { Container } from '../../Container'
@@ -127,6 +128,7 @@ export default withSdk<Props>(({ sdk, entity: entityId }) => {
127128 const hasStates = useHasComponent ( entityId , States )
128129 const hasCounter = useHasComponent ( entityId , Counter )
129130 const hasRewards = useHasComponent ( entityId , Rewards )
131+ const [ gltfValue ] = useComponentValue ( entityId , sdk . components . GltfContainer )
130132
131133 useChange (
132134 ( event , sdk ) => {
@@ -143,15 +145,27 @@ export default withSdk<Props>(({ sdk, entity: entityId }) => {
143145 )
144146
145147 useEffect ( ( ) => {
146- if ( entity ) {
148+ if ( entity && gltfValue ) {
149+ const currentGltfSrc = entity . ecsComponentValues . gltfContainer ?. src
150+ const isChangingGltf = currentGltfSrc !== gltfValue . src
151+
152+ if ( isChangingGltf ) {
153+ entity . resetGltfAssetContainerLoading ( )
154+ }
155+
156+ updateGltfForEntity ( entity , gltfValue )
147157 entity
148158 . onGltfContainerLoaded ( )
149159 . then ( ( gltfAssetContainer ) => {
150160 setAnimations ( [ ...gltfAssetContainer . animationGroups ] )
151161 } )
152- . catch ( ( ) => { } )
162+ . catch ( ( ) => {
163+ setAnimations ( [ ] )
164+ } )
165+ } else {
166+ setAnimations ( [ ] )
153167 }
154- } , [ entity ] )
168+ } , [ entity , gltfValue ] )
155169
156170 const isValidAction = useCallback (
157171 ( action : Action ) => {
@@ -295,7 +309,7 @@ export default withSdk<Props>(({ sdk, entity: entityId }) => {
295309 const handleRemove = useCallback ( async ( ) => {
296310 sdk . operations . removeComponent ( entityId , Actions )
297311 await sdk . operations . dispatch ( )
298- const gltfContainer = getComponentValue ( entityId , GltfContainer )
312+ const gltfContainer = getComponentValue ( entityId , sdk . components . GltfContainer )
299313 const asset = getAssetByModel ( gltfContainer . src )
300314 analytics . track ( Event . REMOVE_COMPONENT , {
301315 componentName : ComponentName . ACTIONS ,
0 commit comments