Forum Discussion
2 Replies
- KevinJardineStart Partner
I would think not as there is no UI for that in the desktop editor. That might be for performance reasons. You could suggest it as an enhancement using the report feature in the desktop editor.
- OverTheEdgeMHCP Member
Agreed, I don't think this is possible right now.
My workaround for this has been to get in the habit of having scripts on separate entities that have a target field. This way I can re-use many small easy to manage scripts on any given object instead of always having to combine all the functionality into a massive script.
Then I might keep these scripts on entities that are children of the entity that I am manipulating. So in my heirarchy the functionality for a given entity is nested inside of it. All just an organizational workaround and preference.As a brief example, the script below sets the material for a separate entity added to the targetEntity field in the editoy. This particular script will change the material of the targetEntity if it is assigned, otherwise it will fall back to changing the material on this.entity (the entity that the script is attached to).
import * as hz from 'horizon/core'; // Import Horizon core module class MaterialComponent extends hz.Component<typeof MaterialComponent> { // Define properties configurable in the editor static propsDefinition = { material: { type: hz.PropTypes.Asset }, // The material to apply targetEntity: { type: hz.PropTypes.Entity, default: null }, // Optional target entity }; start() { // Explicitly type target as hz.Entity to avoid type inference errors const target: hz.Entity = this.props.targetEntity ?? this.entity; // Cast the target to MeshEntity so we can apply the material const meshEntity = target.as(hz.MeshEntity); // If the cast was successful and material is provided, apply it if (meshEntity && this.props.material) { meshEntity.setMaterial(this.props.material); } } } // Register the component so it's usable in the editor and scripts hz.Component.register(MaterialComponent);