Parenting Weapon to Empty = Framerate drops to 2fps

Hello everyone,!

here is a small demonstation of my problem :slight_smile:

http://pn.dyna-studios.com/TA-Problemdemo/WebPlayer.html

If you get to this spear and press E, the weapon is parented to an empty gameObject in the right hand. Then the Weapon follows the Hand perfectly, except the framerate drops to the ground. I’ve been working for days on this issue and I have no idea why this is the case.

The Weapon has no scripts attached to it. I have also made a Screenshot at Runtime:

Screenshot

alt text

Here is my “ItemPickup” Script; it’s attached to the Player:

var clone : GameObject;
var item_name;
var WeaponHand : GameObject;
var WeaponHandParent : GameObject;
var showGUI = false; 

WeaponHand = GameObject.FindWithTag("weaponmount"); //The Tag of The Empty that's parented to the right Hand

function OnTriggerEnter (other : Collider) {
	if (other.gameObject.tag == "weapon"){
    	showGUI = true;		//activate Weapon Pickup Text on collision
}
}

function OnTriggerStay (other : Collider) {
    if (other.gameObject.tag == "weapon"){
    	Debug.Log("WaffenKollision!");          //Collision
    	item_name = other.gameObject.name;
    	Debug.Log("item_name: " + item_name);  // Get the Items Name
    	if (Input.GetKeyDown ("e")){
    	
    		clone = GameObject.Find(item_name);  // Get the Item we are colliding with
    		Debug.Log("clone: " + clone);
    		clone.transform.parent = WeaponHand.transform;
    		clone.transform.position = WeaponHand.transform.position;
    		clone.transform.rotation = WeaponHand.transform.rotation;
    		Debug.Log("Parented !");
                  }
    	
             }
  }
    	
    function OnTriggerExit (other : Collider) {
	if (other.gameObject.tag == "weapon"){
    	showGUI = false;	//deactivate Weapon Pickup Text
    }
}
    	
    	function OnGUI(){
		    if (showGUI){
		    	GUI.Label (Rect (500,500,1000,1000), "[E] Waffe aufnehmen"); //"Press E to Pickup the Weapon"
		    }
    	   
    	  }

I hope somebody has an idea of how to solve this, this drives me crazy.

Greetings from Germany :slight_smile:

Ok, I’ve finally figured it out :smiley:

I have a second PlayerModel that has only 1593 triangles and no animations. I set everything up just like my textured player. Then I moved and grabbed the Spear, and…no performance drop!

That led me to try out my textured player with deactivated animations in script…no performance drop!

I turned the animations back on, pressed play and deactivated the Players “Animate Physics” setting at runtime. Then the Framerate came back from 2 to 9 FPS :slight_smile:

Thanks for your help :slight_smile:

Picture in Fullsize

alt text

I don’t have a good framerate even without the spear attached :smiley: But yes, it get’s worse if i do so. First of all, get rid of the Debug.Logs. In the editor they are really slow especially when executed once per frame. Second, you should deactivate (or remove) the script after you parented the object. Does the spear has a rigidbody attached? Does it have a collider that is not set to trigger? Have you disabled the collision between the spear and your player?

It’s hard to tell what’s wrong here :wink:

(btw. Greetings from Germany :smiley: )