Expand the function you use and confirm you use it correctly:
GetComponent or TryGetComponentA component of the target type must be attached to the same GameObject the function is called on. If the value is null after calling, then this assumption is wrong.
t:ExampleComponent for example).Awake to get, and Start to use.You can use the RequireComponent attribute to automatically add component dependencies when adding new components in the editor.
GetComponentInChildrenOnly components on active GameObjects are returned unless the includeInactive argument is true.
t:ExampleComponent for example).includeInactive argument as true.Awake to get, and Start to use.GetComponentInParentOnly components on active GameObjects are returned unless the includeInactive argument is true.
t:ExampleComponent for example).includeInactive argument as true.Awake to get, and Start to use.If you're still having issues using these methods, it's often preferable to serialize components via the inspector instead.
Double-check the assignment is actually executed.
Your code may not be called because of an incorrect setup like a misspelt method name.