What event should I use if I want my method to be called on a part's destruction? I know this question sounds stupid but I really can't find any tutorial on how to write a custom part modifier script.

Tags
Question

6 Comments

  • Log in to leave a comment
  • Profile image

    If you do a Debug.Log in the awake and/or start methods of your script, can you find them in your log file (or see them in the dev console?)

    4.5 years ago
  • Profile image
    8,392 s5ehfr9

    @NathanMikeska just one more question: the script I attached to one of the game objects under prefab doesn't seem to work. The mesh renderer and colliders do get loaded, so I guess my script is not at the right place. So what should I put the script in?

    4.5 years ago
  • Profile image

    When not warping, regular Unity physics are used, so if you want to modify velocity, you could add force to the parts associated Rigidbody.

    +1 4.5 years ago
  • Profile image

    Depends on where your code is running and what you need. If you are working with a PartModifierScript, there may be a few options. It is a MonoBehaviour, so you can always use OnDestroyed or OnDisabled. There is an overrideable method, OnPartDestroyed, that I believe gets called if the part is destroyed/blown-up in game, despite the game object potentially hanging around (deactivated) for a while. There is also an OnDisposed method, can't remember the exact context in which it gets called.

    +1 4.5 years ago
  • Profile image
    Dev Pedro

    @NathanMikeska

    +1 4.5 years ago
  • Profile image
    8,392 s5ehfr9

    Also, if I want to modify the velocity of the part, should I use something under ModApi or just UnityEngine.Physics ?

    4.5 years ago

No Upvotes

Log in in to upvote this post.