Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
6
Question by Kethis Celebes · Feb 20, 2010 at 03:38 PM · editorinstantiateeditor-scriptingpersist

Programatically instantiating GameObjects to the editor (not during gameplay)

Hello, I am working on a tile based tactics game and would like to be able to use code to instantiate my tiles (and all of the data necessary). I know how to do this at run time, but I need to be able to make exceptions to what the general rules on a case by case basis.

Because of this, I would like to be able to, in the editor, programatically instantiate my network of tiles. From there, I could manually tweak the tiles. I want this to happen not during in-editor game play (CTRL P), so that it and my tweaks persist.

Thank you for your time.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
13
Best Answer

Answer by Lucas Meijer 1 · Feb 20, 2010 at 06:05 PM

The syntax to create gameobjects is the same as in runtime. You can either make a custom editor window to facilitate your game object creation, or use a MenuItem:

//Make sure to place this script in a folder called "Editor"
using UnityEditor;
public class MyTools
{
    [MenuItem("MyTools/CreateGameObjects")]
    static void Create()
    {
         for (int x=0; x!=10; x++)
         {
              GameObject go = new GameObject("MyCreatedGO"+i);
              go.transform.position = new Vector3(x,0,0);
         }
    }
}

good luck, Lucas

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Kethis Celebes · Feb 20, 2010 at 11:26 PM 0
Share

Seems like what I need. Will let you know how it goes - thanks a ton.

avatar image cupsster · Dec 20, 2010 at 08:20 AM 0
Share

Is this possible to archieve in java?

avatar image vargonian · Feb 25, 2013 at 06:49 AM 1
Share

Is there a way to do this without automatically adding the object to the scene?

avatar image ghoulfool · Mar 06, 2014 at 09:53 AM 5
Share

Line 10 should be GameObject go = new GameObject("$$anonymous$$yCreatedGO"+x);

avatar image
1

Answer by Rispat-Momit · Apr 13, 2019 at 08:10 PM

Here is the above script with no errors and with creating the objects through Unity's window GameObject/3D Object

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEditor;
 
 
 public class CreateOBJ : MonoBehaviour {
 
     [MenuItem("GameObject/3D Object/CreateGameObjects")]
 
     static void Create()
     {
         for (int x = 0; x != 10; x++)
         {
             GameObject go = new GameObject("MyCreatedGO" + x);
             go.transform.position = new Vector3(x, 0, 0);
         }
     }
 }

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

Generate 2 gameobjects as child 2 Answers

Editor Script: Linking GameObjects to public script variables resets when playing. 1 Answer

in-editor cloning of game objects 1 Answer

Mark gameobject field as changed from prefab 2 Answers

Custom Inspector: Accessing a reference to another MonoBehaviour? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges