Search Unity

Parenting Prefabs Issue - Fixed

Discussion in 'Multiplayer' started by innercircus, Feb 12, 2010.

  1. innercircus

    innercircus

    Joined:
    Aug 19, 2009
    Posts:
    15
    I've been pounding my head against the wall on this for a while and I feel like I'm just missing some abstract concept.

    What I'm trying to do:
    Using Network.Instantiate to spawn players in a match, then "equip" them with prefabs again using Network.Instantiate based on the player's armor settings.

    Everything seems to work fine accept when I go to parent the instantiated prefabs on each machine. Instead of parenting to the correct character, each of the prefabs are getting assigned to the current player that is executing the RPC. that is to say all the armor goes on one player, the player you control.

    I am looking to attach the equipment prefabs to bones that are found on the correct networkview. However tracing the networkView.viewID of each of the attach points returns the current players networkviewId.

    Code (csharp):
    1.  
    2. @RPC
    3. function equipPlayer(charID : NetworkViewID, WeaponID : NetworkViewID, HeadID : NetworkViewID, info : NetworkMessageInfo)
    4. {
    5.         Application.ExternalCall("unityDebugging","fired the RPC and charID = "+charID);
    6.         var theWeapon: GameObject;
    7.         var theHead: GameObject;
    8.         var thePerson : GameObject;
    9.        
    10.         var weaponItems : GameObject[];
    11.        
    12.         // sort through the items and find our item...
    13.         weaponItems = GameObject.FindGameObjectsWithTag("Weapon");
    14.        
    15.         for (var weapon : GameObject in weaponItems){
    16.             if(weapon.networkView.viewID == WeaponID) {
    17.                 theWeapon = weapon;
    18.                 }
    19.         }
    20.        
    21.         var headItems : GameObject[];
    22.        
    23.         // sort through the items and find our item...
    24.         headItems = GameObject.FindGameObjectsWithTag("Head");
    25.        
    26.         for (var head : GameObject in headItems){
    27.             if(head.networkView.viewID == HeadID) {
    28.                 theHead = head;
    29.                 }
    30.         }
    31.        
    32.         var characters : GameObject[];
    33.         // sort through the characters and find the player...
    34.         characters = GameObject.FindGameObjectsWithTag("Character");
    35.        
    36.         for (var person : GameObject in characters){
    37.             if(person.networkView.viewID == charID) {
    38.                 thePerson = person;
    39.                 // this works great, "thePerson" network ID matches the charID that was passed to the RPC...
    40.                 }
    41.         }
    42.        
    43.         //Now we have the right character and the right item. reparent the item.
    44.         // first - find the attach points we want to parent to.
    45.         var boneGun = "Bip01 R Hand";
    46.         var boneHead = "Bip01 Head";
    47.        
    48.         // PROBLEM!! - these are the attachpoints and they always seem to have the networkView of the player who is running this script.
    49.         var headAP = thePerson.Find(boneHead);
    50.         var weaponAP = thePerson.Find(boneGun);
    51.        
    52.         // using this to display networkviews over the net
    53.         //Application.ExternalCall("unityDebugging","thePerson="+thePerson.networkView.viewID+"--- theHead="+theHead.networkView.viewID+"---weaponAP="+weaponAP.transform.root.networkView.viewID + "---headAP="+headAP);
    54.        
    55.         // parent the items to thePerson.
    56.         theHead.transform.parent = headAP.transform;
    57.         theHead.transform.position = headAP.transform.position;
    58.         theHead.transform.rotation = headAP.transform.rotation;
    59.        
    60.         theWeapon.transform.parent = weaponAP.transform;
    61.         theWeapon.transform.position = weaponAP.transform.position;
    62.         theWeapon.transform.rotation = weaponAP.transform.rotation;
    63. }  
    64.  
    Any insight would be awesome! :) thanks in advance and I love the forums here, they are an excellent source of information and knowledge :)


    UPDATED-FIXED:
    So the problem seems to have stemmed from this issue which I found here:http://answers.unity3d.com/question...iated-gos-nested-in-prefabs-with-getcomponent.

    Passing the full path to the bone I was looking for seemed to fix it all right up! yahoo, now I can get back to actually working!