Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 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
0
Question by Belangia · Oct 20, 2015 at 06:53 PM · editor-scriptingeditorwindowparentingsceneviewextension

Set Parent EditorScript

This is a snip of my code. I am using Editor script to instance obj into the scene. My objects that I am instancing are to replace objects that are already placed. It grabs their positioning and rotation and scale.

The last thing it is supposed to do is grab the parent of the object its replacing then make itself a child before removing the object in question. Everything works except the parenting. Below is my code. let me know if anyone has had any luck.

My usings using UnityEngine; using UnityEditor; using System.Collections; using System.Collections.Generic;

Script Type : EditorWindow

if (GUILayout.Button ("Set_Tile")) {

                     object[] obj = GameObject.FindGameObjectsWithTag (ChoiceTag);
                     foreach (object o in obj) {
                     
                             GameObject g = (GameObject)o;
                             Transform q = g.transform;
                             Position = g.transform.position;
                             if (DistributeOBJ1) {
                                     n = 1;
                             } else {
                                     n = TH.RN ();
                             }        
                             switch (n) {
                             case 1:
                                     Obj1.transform.position = Position;
                                     Obj1.transform.rotation = g.transform.rotation;
             
                     Choose = Obj1;

                                     break;
                             case 2:
                                     Obj2.transform.position = Position;
                                     Obj2.transform.rotation = g.transform.rotation;
                                     Choose = Obj2;
                                     break;
                             case 3:
                                     Obj3.transform.position = Position;
                                     Obj3.transform.rotation = g.transform.rotation;
                                     Choose = Obj3;
                                     break;
                             case 4:
                                     Obj4.transform.position = Position;
                                     Obj4.transform.rotation = g.transform.rotation;
                                     Choose = Obj4;
                                     break;
                             case 5:
                                     Obj1.transform.position = Position;
                                     Obj1.transform.rotation = g.transform.rotation;
                                     Choose = Obj1;
                                     break;
                             case 6:
                                     Obj2.transform.position = Position;
                                     Obj2.transform.rotation = g.transform.rotation;
                                     Choose = Obj2;
                                     break;
                             case 7:
                                     Obj3.transform.position = Position;
                                     Obj3.transform.rotation = g.transform.rotation;
                                     Choose = Obj3;
                                     break;
                             case 8:
                 
                                     Obj1.transform.position = Position;
                                     Obj1.transform.rotation = g.transform.rotation;
                                     Choose = Obj1;
                                     break;
                             case 9:
                                     Obj1.transform.position = Position;
                                     Obj1.transform.rotation = g.transform.rotation;
                                     Choose = Obj1;
                                     break;
                             case 10:
                                     Obj2.transform.position = Position;
                                     Obj2.transform.rotation = g.transform.rotation;
                                     Choose = Obj2;
                                     break;
                             }
                             
             GameObject clone=null;

             clone=PrefabUtility.InstantiatePrefab (Choose) as GameObject;

             (GameObject)clone.transform.parent=g.transform.parent;
                             
                             //DestroyImmediate (g);
                     }
     
             }






I am trying to have my EditorScript get all tagged items into an array, then set the x,y,z of the

Comment
Add comment · Show 1
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 Belangia · Oct 20, 2015 at 03:55 PM 0
Share

Add-Info

What currently happens is as follows-

Setup- GameObject(parent) Child(target)

Code runs before destroying g I set the parent of clone to = g's parent. clone=PrefabUtility.InstantiatePrefab (Choose) as GameObject; (GameObject)clone.transform.parent=g.transform.parent; Child is = g. in the code I grab g's parent then destroy g.

the result is- g is destroyed clone is created clone has no parent

1 Reply

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

Answer by Belangia · Oct 22, 2015 at 08:11 AM

Answer: clone=PrefabUtility.InstantiatePrefab (Choose) as GameObject; creates the prefab as it is in the game folder. Since it has no parent, the file does not parent when being created.

Revert back to using Instantiate(prefab, new Vector3(i * 2.0F, 0, 0), Quaternion.identity); which creates a clone or instance rather than the original. This allows you to edit the parenting relationship once the object has been created within code.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

OnSceneGUI event Use() ates too much :) 1 Answer

Drawing to scene view from EditorWindow? 2 Answers

Custom scene view in editor window 2 Answers

Why does the SceneView camera return jittery values? 0 Answers

Error: Unable to load the icon: 'CustomEditorWindow'. (Custom Scene View) 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