I'm trying to avoid GetComponent calls in my update function because they seem to slow things down when too many are called at once. I've gotten used to just keeping variables that store the components I need in every script. My question is, do .transform .gameObject .rigidbody all count as a .GetComponent...etc or is it just a pointer. If it's a pointer, I'll just call it directly in the update script.
Yes, .transform and .rigidbody are basically the same as using GetComponent(Transform) and GetComponent(Rigidbody). gameObject isn't, because a gameobject isn't a component anyway.
Most are just pointers (I heard that the rule in C# was classes are implicit pointers, and structs aren't. I'm an old C++ programmer, where pointers are explicit.) Many Unity examples use pointer tricks like:
Transform myBullet = Instantiate(bullet, ... , ... ); Rigidbody RB = myBullet.rigidbody; // RB is a ref to the rigidbody bulletScript BS = myBullet.getComponent<bulletScript>(); // BS is a ref to THAT class instance RB.velocity = Vector3.up; // these really do change my bullet, not a local copy BS.lifeSpan = 3;
Many suggestions are to do exactly as you are saying: do all the Find's and GetComponents in Start and save the results.
transform and gameObject are like links say your on youtube and thers a vidio caled transform when you click wach vidio its like typing.transform if that explanes it thats the simplest way i can put it