diff --git a/.vscode/launch.json b/.vscode/launch.json index 977b6c7a7d..b8d9ea128e 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -113,6 +113,12 @@ "request": "launch", "type": "node-terminal", }, + { + "command": "cd packages/network && npm run test", + "name": "npm run test - network", + "request": "launch", + "type": "node-terminal", + }, { "command": "cd packages/engine && npm run test", "name": "npm run test - engine", diff --git a/packages/ecs/src/ComponentFunctions.ts b/packages/ecs/src/ComponentFunctions.ts index e3c9f000a2..bae18ada08 100755 --- a/packages/ecs/src/ComponentFunctions.ts +++ b/packages/ecs/src/ComponentFunctions.ts @@ -359,10 +359,11 @@ export const setComponent = ( root['component'] = Component.name Component.reactorMap.set(entity, root) return getComponent(entity, Component) as ComponentType + } else { + const root = Component.reactorMap.get(entity) + root?.run() } - const root = Component.reactorMap.get(entity) - root?.run() return getComponent(entity, Component) as ComponentType } diff --git a/packages/engine/src/scene/materials/systems/MaterialLibrarySystem.tsx b/packages/engine/src/scene/materials/systems/MaterialLibrarySystem.tsx index fb427ab80f..91c2c70780 100644 --- a/packages/engine/src/scene/materials/systems/MaterialLibrarySystem.tsx +++ b/packages/engine/src/scene/materials/systems/MaterialLibrarySystem.tsx @@ -51,6 +51,7 @@ import { updateMaterialPrototype } from '@etherealengine/spatial/src/renderer/materials/materialFunctions' +import { defineState, getState, useImmediateEffect } from '@etherealengine/hyperflux' import { MeshComponent } from '@etherealengine/spatial/src/renderer/components/MeshComponent' import { MaterialInstanceComponent, @@ -61,7 +62,7 @@ import { Material, MeshBasicMaterial } from 'three' import { SourceComponent } from '../../components/SourceComponent' const reactor = (): ReactElement => { - useEffect(() => { + useImmediateEffect(() => { MaterialPrototypeDefinitions.map((prototype: MaterialPrototypeDefinition, uuid) => createMaterialPrototype(prototype) ) @@ -90,12 +91,13 @@ const MeshReactor = () => { if (source) setComponent(materialEntity, SourceComponent, source) } - useEffect(() => { + useImmediateEffect(() => { if (materialComponent) return const material = meshComponent.material.value as Material if (!isArray(material)) createAndSourceMaterial(material) else for (const mat of material) createAndSourceMaterial(mat) }, []) + return null } @@ -135,8 +137,16 @@ const MaterialInstanceReactor = () => { return null } +export const MaterialLibraryReactorState = defineState({ + name: 'ee.engine.scene.MaterialLibrarySystem', + initial: () => false, + reactor +}) + export const MaterialLibrarySystem = defineSystem({ uuid: 'ee.engine.scene.MaterialLibrarySystem', insert: { after: PresentationSystemGroup }, - reactor + execute: () => { + getState(MaterialLibraryReactorState) + } })