Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Kingda · Nov 16, 2012 at 05:25 PM · instantiatecloneenumbones

Second prefab(Clone) not finding Bones

Ok, Im having an issue with Instantiating a prefab. Currently, Im using Enum to differentiate upgradeable weapon meshes in a prefab. Calling them works fine, and parenting their roots works fine if there is only 1 (Clone) in the scene. The problem occurs when I spawn more than 1 clone. The first clone finds the root bone and parents it correctly, but Unity cant find the second root bone. What gives? Any suggestions would be appreciated!

 #pragma strict
 
 //WEAPON SET ASSIGN SCRIPT//
 
 var character : GameObject;
 var weaponSet : GameObject;
 enum weapon {Weapon01,Weapon02,Weapon03,Weapon04,Weapon05};
 var weaponLevel : weapon;
 
 function Awake () {
 
 print(character);
 
 //find bone transforms
 
 var b_BipRoot = character.transform.Find("b_BipRoot"); 
 var b_Bip001 = b_BipRoot.transform.Find("b_Bip001"); 
 var b_Pelvis = b_Bip001.transform.Find("b_Pelvis");
 var b_LThigh = b_Pelvis.transform.Find("b_L Thigh");
 var b_RThigh = b_Pelvis.transform.Find("b_R Thigh"); 
 var b_LCalf = b_LThigh.transform.Find("b_L Calf");
 var b_RCalf = b_RThigh.transform.Find("b_R Calf"); 
 var b_LFoot = b_LCalf.transform.Find("b_L Foot");
 var b_RFoot = b_RCalf.transform.Find("b_R Foot");
 var b_LToe = b_LFoot.transform.Find("b_L Toe0");
 var b_RToe = b_RFoot.transform.Find("b_R Toe0");
 var b_Spine = b_Pelvis.transform.Find("b_Spine");
 var b_Spine1= b_Spine.transform.Find("b_Spine1");
 var b_LClavicle= b_Spine1.transform.Find("b_L Clavicle");
 var b_RClavicle= b_Spine1.transform.Find("b_R Clavicle");
 var b_Neck= b_Spine1.transform.Find("b_Neck");
 var b_Head= b_Neck.transform.Find("b_Head");
 var b_LUpperArm= b_LClavicle.transform.Find("b_L UpperArm");
 var b_RUpperArm= b_RClavicle.transform.Find("b_R UpperArm");
 var b_LForearm= b_LUpperArm.transform.Find("b_L Forearm");
 var b_RForearm= b_RUpperArm.transform.Find("b_R Forearm");
 var b_LHand= b_LForearm.transform.Find("b_L Hand");
 var b_RHand= b_RForearm.transform.Find("b_R Hand");
 var b_LWeapon= b_LHand.transform.Find("b_L Weapon");
 var b_RWeapon= b_RHand.transform.Find("b_R Weapon");
 
 
 //spawn weaponSet GameObject
 var weaponToEquip = Instantiate(weaponSet, transform.position, transform.rotation);
 
 //find weapon in weaponSet
 var Weapon01 = weaponToEquip.gameObject.Find("Weapon01");
 if (!Weapon01) print("Weapon01 not found");
 
 var Weapon02 = weaponToEquip.gameObject.Find("Weapon02");
 if (!Weapon02) print("Weapon02 not found");
 
 var Weapon03 = weaponToEquip.gameObject.Find("Weapon03");
 if (!Weapon03) print("Weapon03 not found");
 
 var Weapon04 = weaponToEquip.gameObject.Find("Weapon04");
 if (!Weapon04) print("Weapon04 not found");
 
 var Weapon05 = weaponToEquip.gameObject.Find("Weapon05");
 if (!Weapon05) print("Weapon05 not found");
 
 //find weapon root bone
 if (Weapon01){
 var Weapon01_root= Weapon01.transform.Find("/b_Root");<=======Not finding this!
 if (!Weapon01_root) print("Weapon01_root not found");
 }
 
 if (Weapon02){
 var Weapon02_root= Weapon02.transform.Find("b_Root");
 if (!Weapon02_root) print("Weapon02_root not found");
 }
 
 if (Weapon03){
 var Weapon03_root= Weapon03.transform.Find("b_Root");
 if (!Weapon03_root) print("Weapon03_root not found");
 }
 
 if (Weapon04){
 var Weapon04_root= Weapon04.transform.Find("b_Root");
 if (!Weapon04_root) print("Weapon04_root not found");
 }
 
 if (Weapon05){
 var Weapon05_root= Weapon05.transform.Find("b_Root");
 if (!Weapon05_root) print("Weapon05_root not found");
 }
   
  
 //parent, position, and orient weapon to character bones
 if (weaponLevel==weapon.Weapon01){
 if (Weapon01){
 Weapon01_root.transform.position = b_RWeapon.transform.position;
 Weapon01_root.transform.parent = b_RWeapon;
 Weapon01_root.transform.localPosition = Vector3.zero;
     if (weaponSet.tag == "Ranged"){
         Weapon01_root.transform.localRotation = Quaternion.Euler(90,0,0);
     }
     else{
         Weapon01_root.transform.localRotation = Quaternion.identity;
     }
 Weapon01_root.transform.localScale = Vector3.one;
 Destroy(Weapon02);
 Destroy(Weapon03);
 Destroy(Weapon04);
 Destroy(Weapon05);
 }}
 
 if (weaponLevel==weapon.Weapon02){
 if (Weapon02){
 Weapon02_root.transform.position = b_RWeapon.transform.position;
 Weapon02_root.transform.parent = b_RWeapon;
 Weapon02_root.transform.localPosition = Vector3.zero;
     if (weaponSet.tag == "Ranged"){
         Weapon01_root.transform.localRotation = Quaternion.Euler(90,0,0);
     }
     else{
         Weapon01_root.transform.localRotation = Quaternion.identity;
     }
 Weapon02_root.transform.localScale = Vector3.one;
 Destroy(Weapon01);
 Destroy(Weapon03);
 Destroy(Weapon04);
 Destroy(Weapon05);
 }}
 
 if (weaponLevel==weapon.Weapon03){
 if (Weapon03){
 Weapon03_root.transform.position = b_RWeapon.transform.position;
 Weapon03_root.transform.parent = b_RWeapon;
 Weapon03_root.transform.localPosition = Vector3.zero;
     if (weaponSet.tag == "Ranged"){
         Weapon01_root.transform.localRotation = Quaternion.Euler(90,0,0);
     }
     else{
         Weapon01_root.transform.localRotation = Quaternion.identity;
     }
 Weapon03_root.transform.localScale = Vector3.one;
 Destroy(Weapon01);
 Destroy(Weapon02);
 Destroy(Weapon04);
 Destroy(Weapon05);
 }}
 
 if (weaponLevel==weapon.Weapon04){
 if (Weapon04){
 Weapon04_root.transform.position = b_RWeapon.transform.position;
 Weapon04_root.transform.parent = b_RWeapon;
 Weapon04_root.transform.localPosition = Vector3.zero;
     if (weaponSet.tag == "Ranged"){
         Weapon01_root.transform.localRotation = Quaternion.Euler(90,0,0);
     }
     else{
         Weapon01_root.transform.localRotation = Quaternion.identity;
     }
 Weapon04_root.transform.localScale = Vector3.one;
 Destroy(Weapon01);
 Destroy(Weapon02);
 Destroy(Weapon03);
 Destroy(Weapon05);
 }}
 
 if (weaponLevel==weapon.Weapon05){
 if (Weapon05){
 Weapon05_root.transform.position = b_RWeapon.transform.position;
 Weapon05_root.transform.parent = b_RWeapon;
 Weapon05_root.transform.localPosition = Vector3.zero;
     if (weaponSet.tag == "Ranged"){
         Weapon01_root.transform.localRotation = Quaternion.Euler(90,0,0);
     }
     else{
         Weapon01_root.transform.localRotation = Quaternion.identity;
     }
 Weapon05_root.transform.localScale = Vector3.one;
 Destroy(Weapon01);
 Destroy(Weapon02);
 Destroy(Weapon03);
 Destroy(Weapon04);
 }}
 
 
 
 }
 function Update () 
 {
 
 }
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

0 Replies

· Add your reply
  • Sort: 

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

9 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Instantiate without (clone) in JS. 1 Answer

Instantiated GameObject's components are disabled 3 Answers

Auto Translate after cloning gameobject using Instantiate() 1 Answer

Instantiating a random dropped consumable item from many cloned objects 1 Answer

How do I make an object clone itself? 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