- Home /
Component values don't get assigned
So I've got a Script named Item, which isn't attached to a prefab. Then I have a Gameobject with a Script attached named ItemDatabase. In this script I 'm reading from a json-file all necessary values. I'm then creating an Item-object and fill it with the values from the json-file I read from. Afterwards I put all created item-objects to a public list.
Now I want to create a gameobject for the item, that I do with instantiate and add the item-component on runtime. I already got my list with the items from the ItemDatabase, but when I'm trying to add the Item-component to the instantiated game object, none of the values get assigned, except for I'm assigning them specifically.
Item itemComponent = slotsItems_gameObject.AddComponent<Item>();
// I would now expect this lins is working, which doesn't
itemComponent = databaseItemsShop.items[0];
// I don't see the value in the inspector and when I use Debug.Log(itemComponent.description) for example it's null
// but this works
itemComponent.description = databaseItemsShop.items[0].description;
// Then I see the description value in the inspector and I can Debug.Log it.
So why can't I assign the "whole" component variable. I know, if I know assign all attributes individually, it will work. But I just don't get, why this has to be like this.
ps. sorry for maybe wrong topic tag