- Home /
Why does this have to be in an update method?
All I wanted to do was move the centre of mass of a rigid body, but it wouldn't work unless I put it in an update, like this.
using System.Collections;
public class CoM : MonoBehaviour {
void Update() {
rigidbody.centerOfMass = new Vector3(0, 0, -2);
}
}
I just don't see why you can't put it in a custom method like "void MoveCenter()".
Btw I'm learning Unity3d and C# at the same time.
Answer by Unitraxx · Apr 14, 2013 at 11:53 AM
instead of placing it in Update(), place it in Start()
void Start() {
rigidbody.centerOfMass = new Vector3(0, 0, -2);
}
Update() gets called every frame, Start() only once in the beginning. If you would place it in MoveCenter() it would never get called.
Ah. Thanks.
I guess the Unity Engine doesn't call custom methods. That's why we have start?
If you want custom methods to be called, you call them yourself from Start(),Awake(),Update().. depends on what behaviour you want. If I helped you out, please click the check-mark on the left of my answer. :)
Unity does not directly call custom methods, because it doesn't even know they exist! You have to call them yourself.
Syclamoth - Yes I get it now, finally! It makes sense. I didn't before - I was just doing things parrot fashion, but now things are starting to fall into place.
Your answer
Follow this Question
Related Questions
Are Apple's iOS promo codes version-dependent? 1 Answer
My variable doesn't update real-time? 2 Answers
I have been struggling with a GUI window with table data for over a week now. What am I doing wrong? 1 Answer
Im a bit confused on a simple script 1 Answer
How to cycle Vector3 transformations correclty perfomance-wise? 1 Answer