Destroy rigidbody and recreate it in script

If i use:

Destroy(rigidbody);

      GameObject.Find("Boat").AddComponent(Rigidbody).

to destroy old rigidbody and create a newone with different settings the new rigidbody is not created, anyone knows why?

Maybe it is because of wrong name. What I mean is you have to have your object ‘Boat’ with capital B just like Boat in the script. If it’s wrong, then it will be not working.

Thnx but my objectname is Boat with capital B so the problem should be somewhere else

Strange!!! Can you tell me why you want to remove the component and add it again? Maybe you can change the setting through script right away instead of recreate.

Back to your problem, why don’t you just use :

gameObject.AddComponent(Rigidbody) instead of searching gameObject in the scene.

because when the scene starts i have to have a rigidbody for boyancy script, after when i want to control the boat i have to destroy it, and when i wanto to stop contro rigidbody should appear again…

Don’t destroy it - just set the kinematic flag to true, do your control stuff, and then set it to false again. Assuming you’re not controlling your boat with physics.

Unfortunatly i have physics… my boat is a boyant object:(

Then why are you destroying the rigidbody in the first place?

because when i start to control it i use a script that create a rigidbody by itself

Still dont understand why you need to remove the rigidbody tbh…

because if i leave regidbody on i can’t control the boat, it wont move at all

How are you trying to control the boat?

If you have rigidbody (no kinematic)… use forces ·_·!

There it is. Just remove the rigidbody creation from THAT script.

tbh, I think you just need to get a better understanding of how they work.

You can use

rigidBody.AddForce to move it, or Transform.Translate.

Both will work without removing the rigidbody, and if they dont, youre doing it wrong.