Hey guys,
I just want to make sure I understand something correctly. The following code is bad practice because GetComponent<> has a significant performance cost so running it several times a second would slow the game down:
void Update() {
ADifferentGameObject.GetComponent<AScriptOnThatGameObject>().SomeString = "SomeValue";
}
But the following is just fine because I first cache the script:
AScriptOnThatGameObject MyScriptOnThatGameObject;
void Start() {
MyScriptOnThatGameObject = ADifferentGameObject.GetComponent<AScriptOnThatGameObject>();
}
void Update() {
MyScriptOnThatGameObject.SomeString = "SomeValue";
}
Is this right? Thanks in advance!