I'm trying to make a scrolling inventory system in unity using button UI elements. I made a template for a button which is not a prefab and instantiated a game object with that template, which should make a clone of the template. Instead of that it acts like a prefab and gives me an error.
I happened to find a tutorial that worked well enough. I followed this tutorial up to the point where I had to set the parent of the instantiated gameObject. The tutor did this without trouble. I have not tried contacting the person who made this tutorial as it is more than 2 years old at this point and the channel hasn't been active for at least 7 months. I tried changing his code and removing the button prefab. I found a similar problem on this site, but the solution didn't work for me.
[SerializeField]
private GameObject itemTemplate, inventoryTabWeapons;
private GameObject item;
public void GenerateItem(string name)
{
item = Instantiate(itemTemplate) as GameObject;
item.SetActive(true);
item.transform.SetParent(inventoryTabWeapons.transform, false); //This line is where the error brings me to.
}
I would like to post screenshots of the results here, but I apparently don't have enough reputation points.
expected result: The button should be made a child to ListContent, which is set as inventoryTabWeapons in the inspector.
actual result: The button isn't a child of anything.
I get the following error:
Setting the parent of a transform which resides in a Prefab Asset is disabled to prevent data corruption
No prefabs were used for this code and the only asset that has its parent changed is a clone of a template, so this error makes no sense to me.