GameObject.Find(string) doesn't work the first time, but then works fine on each test afterward.

I have some code which tries to assign a GameObject:

example1.GetComponent().bar = GameObject.Find(barStr1);

When I load up the editor and hit the Play button, the first time this line of code is executed it fails to assign the GameObject to ().bar. However, once I stop the game, then eventually press Play again, the game is restarted but the script runs perfectly and is able to assign the GameObject properly every time for the rest of my session. Until I quit out of the editor.

Is the object you’re finding in the scene at edit time, or does it get generated by some script, maybe in a Start() or Awake() method?

This sounds like a race condition, as alluded to by PraetorBlue. Can you provide at least the general structure of the code including the (presumably) scripted instantiation of the object named barStr1 and where you’re calling GameObject.Find on it?