- Home /
Instantiate in edit mode, utilizing billboarding
I want to put a grid of objects (cornstalks) on the terrain in edit mode (as if a farmer had planted North/South, then again East/West) so that I can delete some in a pattern, leaving a corn maze. Creating the grid in play mode doesn't allow me to edit the maze paths out. When I run the "DO CORN" from the context menu (see below), the _sphere's script is called successfully (confirmed by the debug.log), but nothing gets placed on the terrain in edit mode. What am I missing?
I'm not sure this is possible to do while still using the "billboarding" that Mass Place Trees uses, as I'm aware that just placing thousands of cornstalk objects will lag horribly. If I have to brush in the whole terrain of corn stalk "trees" I will, but a properly planted corn field grid would be much cooler. I'm a hs teacher dabbling in Unity, so these scripts are cobbled together.
I've tried so far:
Using a context menu to call another script (works as indicated by debug.log)
The second script does create the desired grid, but only in play mode.
Various combinations of the "execute in edit mode" on the second script.
Here's some images of my inspector.
My 2 scripts:
MakeCorn.js
// JavaScript
//@script ExecuteInEditMode()
var mySphere : GameObject;
function Start () {
Debug.Log ("I found the MakeCorn script and theMakeCornFunc function!");
for (var z = 10; z < 50; z+=2) {
for (var x = 10; x < 50; x+=2) {
yield WaitForSeconds(.01);
var corn = Instantiate(mySphere);
mySphere.transform.position = Vector3 (x, 0, z);
}
}
}
MyContxtMenu.js
var objectwScript : GameObject;
//@script ExecuteInEditMode()
@ContextMenu ("Do CORN")
function DoSomething () {
//Debug.Log ("I'm trying to access the instantiate corn script");
objectwScript.GetComponent(MakeCorn).Start();
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613143629im_/https://answers.unity.com/themes/thub/images/avi.jpg)