scripting help(issue)

hi to all,
I am trying to delete the components of the object and again add the components to the same object in a same frame.I tried destroy function and destroyimmediate function but both seems to me like takes times to delete objects so giving me error.
if(gameobj1)
{
gameobj1.GetComponent(“rope_test”).DeleteObjects();
gameobj1.transform.DetachChildren();
DestroyImmediate(GameObject.Find(“TubeRenderer_” + gameobj1.name));
DestroyImmediate(GameObject.Find(“Cube3”).GetComponent(“CharacterJoint”));
DestroyImmediate(GameObject.Find(“Cube3”).GetComponent(“Rigidbody”));
gameobj1 = “”;

}
else
{
gameobj1 = GameObject.Find(“Cube1”);
gameobj1.AddComponent(“rope_test”);
gameobj1.GetComponent(“rope_test”).target = GameObject.Find(“Cube3”).transform;
gameobj1.GetComponent(“rope_test”).Awakee();
}
In the above code adding and deleting the components done in separate frames and works fine. But i wanted the code like below which do both in same frame

if(gameobj1)
{
gameobj1.GetComponent(“rope_test”).DeleteObjects();
gameobj1.transform.DetachChildren();
DestroyImmediate(GameObject.Find(“TubeRenderer_” + gameobj1.name));
DestroyImmediate(GameObject.Find(“Cube3”).GetComponent(“CharacterJoint”));
DestroyImmediate(GameObject.Find(“Cube3”).GetComponent(“Rigidbody”));
gameobj1 = “”;

}
gameobj1 = GameObject.Find(“Cube1”);
gameobj1.AddComponent(“rope_test”);
gameobj1.GetComponent(“rope_test”).target = GameObject.Find(“Cube3”).transform;
gameobj1.GetComponent(“rope_test”).Awakee();

in this code i got error saying " can’t remove component rigidbody because rope_test(script) depends on that"

Please give me suggestions to fix this.Thx in advance

regard’s
rajesh

Hello,

  • In your code, where is “rope_script”? I only see “rope_test”

  • Use “rigidbody.detectCollisions = false;” to deactivate the collisions of a gameobject, I found it very useful.

my typing error its rope_test only

Guys need help.Thanks in advance