Create a Prefab directly inside a GameObject (not SetParent or transform.parent)
I need to instantiate a prefab inside a GameObject in an UI, which uses an horizontal layout group that saves some sort of "track" panels. , however, if i drag directly the prefab from the editor it will give a different result that if i use SetParent or transform.parent after using Instantiate(prefab).
This is what happens if i grab them from the editor and drag them to the GameObject that has the layout:
http://i.imgur.com/wFlr6Uw.png
However, after executing the program, it goes like this:
http://i.imgur.com/DTlf9FW.png
Not only you can see the shape of the tracks are out of the parent gameobject (which is the scrollbar), but the game view looks off.
Is there any way to recreate the action that grabs the prefab from the editor to the layout UI gameobject?
These are the pieces of code i tried:
Instantiate(_track).transform.SetParent(_trackViewer.transform);
Another one:
GameObject track = Instantiate(_track);
track.name = p.tracks[i].Name;
track.transform.SetParent(_trackViewer.transform);
_editorTracks.Add(Instantiate(track));