The question is answered, right answer was accepted
How can i find a GameObject.transform with a concatenated string
I am trying to find a GameObject with a concatenated string. "SpawnPoint" + raceData
When i hard code the complete string it finds the GO, but when using the concat above it doesnt.
public RaceData raceData
public GameObject charCreation;
public void SelectRace() {
charCreation = GameObject.Find("CharacterSelectCreate");
string loc = "SpawnPoint" + raceData;
raceLoc = GameObject.Find(loc).transform;
CreationManager = charCreation.GetComponent<CharacterSelectionCreationManager>();
CreationManager.spawnPosition = raceLoc;
}
Anyone got an idea? thanks in advance
I can't tell what RaceData is, and that's key to answering your question. How does RaceData become something a string can concatenate? Have you used debug to see what loc becomes, to know that it is factually a match for a name? What OS are you on, are you using Visual Studio?
thanks for pointing me in the right direction @JVene . the raceData gave the name of the prefab and not the name of the actual race. simply adding the raceData.raceName solved the issue.
Follow this Question
Related Questions
(Solved) Findout if an object exist in the scene, but dont trow exception 1 Answer
How Can I assign a gameobject via script? 0 Answers
How to find the "youngest" Game Object? 1 Answer
setting a variable to a GameObject that has a certain RGB value??? please help 0 Answers
GameObject.Find throws be a error when trying to find a child. 1 Answer