Identifying Prefabs without using strings?

I’ve been reading 50 Tips for Working with Unity (Best Practices) and best practice #34 confused me.

  1. Don’t use strings for anything other than displayed text. In particular, do not use strings for identifying objects or prefabs etc. One unfortunate exception is animations, which generally are accessed with their string names.

How is it possible to access objects and prefabs without using strings (for their names)?

I know there’s tags and types, but I’ve heard they’re slow.

It’s difficult to describe, but your objects should ‘already know’ what they need to know. Rule 34 (bahaha) should really be considered more of a guideline, since there are certain things that can only be done via string access.

Does your player have a gun? Don’t find it by name. Find it by relation. Your player should have a gun variable anyway; assign it in the inspector or during runtime when you create/swap to that gun.

If you use a string for something, it’ll be slower than a direct reference and harder to debug/maintain your code. Unity can help with references but if you change an object name and forget to change it in code, the entire universe will implode.