From 0e66e475f198f7aabb12769a130cd9faa81b2a7c Mon Sep 17 00:00:00 2001 From: Appaji <52322531+CITIZENDOT@users.noreply.github.com> Date: Wed, 29 May 2024 21:09:43 +0530 Subject: [PATCH] Fix infinite loading in `VariantComponent` (#10267) * Use `useOptionalComponent` instead of `useComponent` * Use `getOptional` instead of `useOptional` --------- Co-authored-by: Gheric Speiginer --- .../editor/src/components/properties/VariantNodeEditor.tsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/editor/src/components/properties/VariantNodeEditor.tsx b/packages/editor/src/components/properties/VariantNodeEditor.tsx index 7516bcbca0..c42cdc5fab 100644 --- a/packages/editor/src/components/properties/VariantNodeEditor.tsx +++ b/packages/editor/src/components/properties/VariantNodeEditor.tsx @@ -27,7 +27,7 @@ import DeblurIcon from '@mui/icons-material/Deblur' import React, { useEffect } from 'react' import { useTranslation } from 'react-i18next' -import { useComponent } from '@etherealengine/ecs/src/ComponentFunctions' +import { getOptionalMutableComponent, useComponent } from '@etherealengine/ecs/src/ComponentFunctions' import { Entity, UndefinedEntity } from '@etherealengine/ecs/src/Entity' import { AssetLoader } from '@etherealengine/engine/src/assets/classes/AssetLoader' import { AssetType } from '@etherealengine/engine/src/assets/enum/AssetType' @@ -96,11 +96,12 @@ export const VariantNodeEditor: EditorComponentType = (props: { entity: Entity } const { t } = useTranslation() const entity = props.entity const variantComponent = useComponent(entity, VariantComponent) - const modelComponent = useComponent(entity, ModelComponent) const previewIndex = useHookstate(0) const setPreview = (index: number) => { previewIndex.set(index) + const modelComponent = getOptionalMutableComponent(entity, ModelComponent) + if (!modelComponent) return modelComponent.src.set(variantComponent.levels[index].src.value) }