In my UI, I have a “container” section with a horizontal layout group, and my script fills this at run time with prefabs of some UI elements. The horizontal layout group automatically lines everything up and spaces them out, so it looks right no matter how many prefabs I spawn into the group.
Everything to this point is working right.
for (int x = 0; x < GameManager.RM.FindNumberOfStagesForThisWorld(HighlightedWorld); x++)
{
StageBlocks[x] = Instantiate(StagePrefab, StageContainer.transform);
StageHelper Helpr = StageBlocks[x].GetComponent<StageHelper>();
// followed by a bunch of code to set up the visual style of these elements
}
But I’ve also got a little cursor that moves around to these prefabs. I was simply going to move the position of this element to match the position of the prefab, like so.
StageCursor.transform.position = StageBlocks[HighlightedStage - 1].transform.position;
But the problem is that this position isn’t in the correct place. It’s plopping it out into the corner of the container.
The best I can figure is that it is reading the transform position of where the prefab was spawned, not where it is being displayed as being, since the horizontal layout group is adjusting its position.
If there’s something else that could be causing this, I’d be interested in knowing, but I can’t quite fathom what.