I’m making some AI and I’m using this line a lot:
GetComponentInParent();
I know it’s bad practice t call this too often, and I’d like to cache it if possible.
There is a good chance if there are multiple game objects interacting at once, it may get called a dozen times.
Normally I cache components, however, I’m not sure how to do this with a script? or if it’s even possible?
I’ve tried this: Component parentScript = GetComponentInParent();
however, later on, when I try to get public variables like: parentScript.health, it doesn’t pick it up.
Does anyone know if it’s possible to cache a script component? (Or at the very least, link up variables some how?)