So, I have a little problem with ArrayMaker, a Prefab and Parenting.
Here is what I am trying to do:
For a 2D Game we made a Menu, a nice 2D-Book. When the Character gets a Quest, a new Page should be visible with Information and so on. So, the idea was to have an ArrayList which contains these Pages, and everytime the Player gets a new Quest a new GameObject-Item is added to the list. When that happens a new Page is created from the Page-Prefab-Object and parented to a certain Object in my GUI.
I'm testing this right now with a little Box (a future NPC
) which triggers an Event on Collision and sends the "NEWQUEST"-Event to the FSM which manages the ArrayList and the Creation of the Pages.
The Scene-Structure of the GameObjects:
The FSM has got one GameObject-Variable:
The ArrayList has no prefilled Items:
In the very first state I check if there is already an Item in the Array with the "Contains"-Method:
If it's false, I'm creating an Object (choosing the Prefab "Page" and storing the Object into the GameObject-Variable)
Then I add the Item to the ArrayList:
Find the Object:
And then I set the parent:
IF the Player rans into the box again, of course the "Contains"-Method is checking again, and this time it will say it's true, since an Item was added to the ArrayList before. There I do almost the same but FIRST I do add the Item to the List and THEN I create a Page from Prefab, find and parent it.
So, what's the problem? The parenting. The first time it works just fine:
But after that it doesn't parent the object anymore. It just creates them in the Scene:
It's adding the items into the ArrayList, but does not parent them.
Where's my mistake?
!EDIT:!
I also noticed something. Seems like a bug to me:
- when attaching an ArrayList-Component to an Object and not filling it with Items (leaving the Prefilled Count at 0) and the game plays, it is not prefilled, but as soon you modify that Value and set it back to 0 as soon as you hit play it is prefilled EVERYTIME!
I think this is not intended...
!EDIT2:!
Made some tests with no ArrayList. OnTrigger I create the Prefab-Object and Parent it. The First time it's okay, but then it just creates in the scene, and not as a child of the selected GameObject.
It's definitely a problem with Parenting and not my Array-Structure. The Prefab is tagged with "GUIPAGE" and of course all the created Instances are also tagged with "GUIPAGE". Is this a problem? It seems it can't find the Object with its tag after the first creation again...also using the Name of the Object ("Page(Clone)") does not work.