R
R
Relayz2021-04-13 15:36:52
Unity
Relayz, 2021-04-13 15:36:52

How to fix "Cannot instantiate objects with constant parent"?

Good day, gentlemen and ladies.
There was a problem creating the object.

The following script hangs on the character, which stores empty objects in itself:

Script
L4CyO.png

Accordingly, there is a store that stores ScriptlObjects with all the models I need.
Score
L4CyR.png


The main problem is that if, when creating an object in the Player Clothes script, as transform, select the first cell to create (that is, Element 0 - GameObject), then it will create absolutely any object without any interference.
If you try to create on any other transform, then the following error pops up:
Mistake
60758c343f6db534690661.png


The method itself:

Method
public void WearClothes(StoreSlots storeSlots)
    {
        if (storeSlots.StoreEntity != null)
        {
            index = storeSlots.slotID;
            if (storeSlots.accsesType == StoreSlots.Accses.Opened)
            {
                Instantiate(storeSlots.slotModel,_clothes[index].transform);
            }
        }
}


When trying to set code like this:
The code
public void WearClothes(StoreSlots storeSlots)
    {
        if (storeSlots.StoreEntity != null)
        {
            index = storeSlots.slotID;
            if (storeSlots.accsesType == StoreSlots.Accses.Opened)
            {
                GameObject cloth;
                cloth = Instantiate(storeSlots.slotModel);
                cloth.transform.parent = _clothes[index].transform;
            }
        }
}


The following error comes up:
spoiler
L4Ddi.png

Help me please.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question