I’m trying to access a script method from the editor.
The Terrain Generation script works great, but I don’t want to do it at runtime. Instead I want to run the generation once within the editor.
It it possible to access the instance of the Terrain object from the editor?
I know I can access the component data with a call like editor.call('entities:selectedFirst').apiEntity.get('components.script.scripts.terrain'), but I’m not wanting to manipulate the editor attributes directly. This doesn’t appear to be an instance of Terrain.
This topic doesn’t seem to cover accessing the script in the editor as entity.script isn’t set.
As far as I know script type instances aren’t spawned in the pc.Application instance running in editor. I am not sure if there are plans to do that with the new editor-api.
Though I think you can still do it. I’ve done something similar in the past to get terrain generation working in editor. Check this post, uses a community framework to get a script instance running in editor:
Thanks for the quick answer and great solution! How did you go about keeping the mesh? I’m going down the path of exporting as a model, saving as an asset and then setting the render/collision components. Is there a smarter way?