#it tells the prefab where to go

1 messages · Page 1 of 1 (latest)

spiral glacier
#

I need more information. Please show me the definition of RecipeButton.

spiral glacier
#

okay, so it stores a Transform, doesn't actually set the parent of its own transform

#

got it

#

so, this should create two buttons and parent them to two different places

spiral glacier
#

this code.

#
            GameObject recipeButton = Instantiate(recipeUiButton, recipeButtonParent);
            RecipeButton recipeButtonComponent = recipeButton.GetComponent<RecipeButton>();
            recipeButtonComponent.ConfigureButton(recipe);
            recipeButtonComponent.SetParent(recipesParent);

            // Déterminez le parent en fonction de la catégorie
            Transform categoryParent = GetCategoryParent(recipe.categoryName);
            recipeButton.transform.SetParent(categoryParent);

            recipeButtons.Add(recipe, recipeButton);

            GameObject recipeButton2 = Instantiate(recipeUiButton, recipeButtonParent);
            RecipeButton recipeButtonComponent2 = recipeButton2.GetComponent<RecipeButton>();
            recipeButtonComponent2.ConfigureButton(recipe);
            recipeButtonComponent2.SetParent(recipesParent);

            // Déterminez le parent en fonction de la catégorie
            Transform categoryParent2 = GetCategoryParent(CategoryName.All);
            recipeButton2.transform.SetParent(categoryParent2);

            recipeButtons.Add(recipe, recipeButton2);
#

it creates a button and parents it to the specific category parent

#

then it creates another button and parents it to the "all" category parent

wheat apex
#

i have this error
ArgumentException: An item with the same key has already been added. Key: AxeRecipe (RecipeData) System.Collections.Generic.Dictionary2[TKey,TValue].TryInsert (TKey key, TValue value, System.Collections.Generic.InsertionBehavior behavior) (at <391154401d904e0ca279fe00c621b01b>:0)
System.Collections.Generic.Dictionary2[TKey,TValue].Add (TKey key, TValue value) (at <391154401d904e0ca279fe00c621b01b>:0) CraftingSystem.UpdateDisplayedRecipes () (at Assets/Scripts/Crafting/CraftingSystem.cs:112) CraftingSystem.Update () (at Assets/Scripts/Crafting/CraftingSystem.cs:73)

spiral glacier
#

well, now you have two buttons for the same recipe

#

so your dictionary already has that recipe as a key

#

do you ever actually use the dictionary to get a button from its recipe?

#

I only see you using recipeButtons in the method that removes all buttons

wheat apex
spiral glacier
#

if it's only used to keep a list of buttons, you can just make it a list

wheat apex
#

I have another question

#

is it possible that when you open the menu, it shows the All category as selected?

spiral glacier
#

do you have a way to change which category is shown?

wheat apex
#

thats my code for the category

wheat apex
#

Do you have an idea

spiral glacier
#

bad link

#

you didn't copy the link after making the paste

wheat apex
wheat apex
#

Do you have an idea ?

wheat apex
#

@spiral glacier when I craft an item, it duplicates the buttons

wheat apex
#

??