Accessing script methods from the editor

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.

image

This topic doesn’t seem to cover accessing the script in the editor as entity.script isn’t set.

image

Thanks for any help.

Hi @_Undefined,

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:

3 Likes

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?

If you are going that way, then why not create your terrain model in Blender or a similar app and import the model in editor?

But you may not have to, if you can have script generate the same terrain both in editor and on runtime then you are set. There is no need to have the terrain in a model file.

1 Like

I’m was thinking to be able to edit the mesh in the editor and save it… but yeah, blender! Thanks for the help!

1 Like