Forum Discussion

Weirdbob95's avatar
2 months ago

Editing many models' motion properties

I'm trying to import a lot of very large custom models, each of which have hundreds of sub-models. When I spawn a model by dragging it into the editor or by spawning it at runtime with a script, all of the sub-models are static by default (motion set to None). I need all the sub-models to be non-static (motion set to Animated) so that the rest of my scripts can finish setting them up and later animate them during gameplay. Is there any good way to accomplish this right now?

Things I've tried:
- Dragging the models into the world and editing them with the Hierarchy and Properties windows has two problems. First, when I spawn a model by dragging it into the world, about 20% of the submodels are randomly offset from the their correct positions. This is nondeterministic, different submodels are affected every time. Fixing each submodel is not practical when there would be a total of thousands of errors. Second, while I can multiselect all the submodels and set their Motion properties all to Animated at once, this action doesn't reliably affect all the submodels, but a fraction of them are unaffected. I again can't edit all the submodels one at a time since there are thousands of them.
- Spawning the models at runtime with a script makes them static by default. I can't find any APIs to spawn a model as Animated or to change its motion at runtime. Does any API to do this exist?

1 Reply

  • First, your Asset's/Model's will need to be set to Animated and re-saved as an asset if you have not done so already. Another method you can try is put sub-models under an Animated parent/root and drive animation on the parent. This avoids relying on child motion flags at spawn. This follows from the motion-type rules in the tutorials in the official doc's. The Doc's in this link cover how to spawn objects at runtime.

    https://developers.meta.com/horizon-worlds/learn/documentation/desktop-editor/objects/object-spawning-and-despawning 

    When you spawn an asset/template at runtime, Horizon is probably trying to rebuild that object from the asset data so its motion type may reset to default (Static). So, every time you spawn a fresh copy what could be happening is the engine is treating it like a “cold start,” and your animations start in the off state.

    Also, another option is "Pooling" instead of spawning which skips that cold rebuild entirely if that is what is causing that issue. When you use pooling you pre-spawn (instantiate) the object once at world start or during preload. If you want to use pooling to resolve this issue make sure you configure it exactlky how you want it, motion type/animated, physics, bindings. Hide or move it when not in use so when 'Spawning" with pooling which is not actually spawning it and acts as if it isn't even in the world, you're just re-activating that existing object that's already animated.