Hello.
This is the first game I’m working on.
So here I’m going to describe as best as I can something weird that happened.
I want my player’s character to be able to dual wield weapons.
So I created two game objects named “Right Hand Slot” and “Left Hand Slot” each representing a weapon slot for the dual wielding. In each object I added a script “HandSlot” which has the necessary code.
I was trying out ideas for the prototype phase in a scene, and the system worked correctly.
At some point I decided to make a new scene, and so I did.
I added to it all the necessary prefabs, but something was not working correctly. The player couldn’t equip weapons any more. Through debugging I discovered that the lines with this code:
rightHandSlot = GameObject.Find("Right Hand Slot").GetComponent<HandSlot>();
leftHandSlot = GameObject.Find("Left Hand Slot").GetComponent<HandSlot>();
didn’t assign the respective HandSlot components, even though they were finding the game objects that had these components. And that was happening for both scenes.
I tried different things, and eventually I changed the names of the objects that have the HandSlot components from “Right Hand Slot” to “RightHandSlot” and from “Left Hand Slot” to “LeftHandSlot”, and of course I changed the code in the scripts from what it was to:
rightHandSlot = GameObject.Find("RightHandSlot").GetComponent<HandSlot>();
leftHandSlot = GameObject.Find("LeftHandSlot").GetComponent<HandSlot>();
and much to my surprise, that fixed it!
As if for some unknown reason I had to change the name of some random game objects because I created a new scene.
The whole story surprised me so much, I felt I had to share it.