Crafting System

Alright that import went well, but I have a few more questions:

  1. How does the list update multiple recipes? So far I only see one, without any icons, name or anything (apologies if the questions are repetitive, I’m just… baffled)
    1a. The demo recipe that gets deleted was the one in the prefab right?
  2. Do you update the icons in the Ingredients, or…?
  3. If you have multiple Crafting Recipe Scriptable Objects, do you create a Recipe and Ingredient Prefab for each one individually, or…?
  4. The script that goes into the demo recipe is the ‘RecipeUI.cs’ script, right? (It didn’t properly import, so I’m guessing now…)

Right now, deleting the demo Recipe prefab shows me just this:

Again, significantly better than before (thank you @bixarrio ), but images are not automatically updated (I can manually update them, but is this really the point…?)

And this is what my Hierarchy looks like, right now (I placed the demo recipe back for testing purposes…). As you can see, the recipe is there, but it does nothing to the UI:

Edit: Silly me… Should’ve just created the recipes in the resource folder directly instead. My bad

and thanks again so so so much @bixarrio for guiding me through this wild task. You did me a big favor with this one! (By the way, do you give me permission to use this system in my own game? Please? :slight_smile: )

  1. The system discovers all the recipes in the resources folders and adds them to the list. With the updates, the recipes have to live in a Recipes folder under Resources
    1a. No, the prefab is a container for a recipe, not a specific one. An instance of the prefab is created and the image and text is filled with the data from the scriptable object. The demo recipe is the one in the /Resources/Recipes/ folder

No, the icons are retrieved from the InventoryItem that is set as the ingredient

No, you don’t need any more prefabs. When the crafting system calls Setup on RecipeUI it passes the Recipe scriptable object and the script (RecipeUI) populates the fields in the UI

I don’t know what this means? There is no script that goes into any recipe

You are not supposed to delete any prefabs. You only delete the Healthy Hat Recipe from /Resources/Recipes/

You can do whatever you want with it.

1 Like

That’s fair, I’ll review all the steps again right now. Next step, if you’re still up for a wild challenge :stuck_out_tongue_winking_eye: , is to make these based on a trait level known as ‘Traits’ (just to keep the levelling system exciting). I’ll give this a go on my own first :slight_smile:

I never did the fourth course in this series so I don’t know what the traits are. However, I have the code from the repo, so I can take a look at it and possibly come up with something. I can also just find the relevant videos in the course and take a peek if I need guidance. I suspect it would be as simple as creating a subclassed recipe (so the current recipe scriptable object would need a little refactor) and then we’d probably add some type of filter.


Edit
Traits are a little odd for crafting. A player can only craft something if he’s quick enough? Usually recipes are unlocked when a player has discovered all the ingredients for recipes. Or completing a quest may also grant recipes. This would mean we have to keep a list of known recipes on the player and save these along with other player details. The system for this isn’t too difficult to achieve; Add a unique id to the recipes (the way inventory items do), create a component that will hold these known recipes (something like PlayerKnownRecipesStore), and add a filter to crafting tables to filter out the recipes and only give the known recipes to the UI

Im honestly debating between a XP based system, and a traits based system… Frankly speaking though, if we can get an XP based system that would be marvelous (it just feels more natural to me. Traits? Not for skilling XP tbh, I mean why would I fight to level up and get points to craft when I can craft to level up crafting instead…?!).

Edit: @bixarrio let’s try an XP-based system, and we can mix that idea with your idea of discovering ingredients and/or recipes, prior to being able to craft stuff out of them. Traits for crafting just don’t sound natural at all to me, but instead of completely hiding them, we can make their transparency at 50% until they’re unlocked, hunting to something yet to be discovered

What does this mean? You can only craft certain things if you are at a certain level?

@bixarrio Yup, that’s the point. I was wondering if we can do that for other systems as well (I have a baby resource gathering system that can drastically benefit from this). In other words, similar to how combat works in this game, we develop an XP-based system that levels specific skills if they are trained well by the player (and if its generic, that would be phenomenal!). I am yet to think about the UI for this, but it’s a start for now. (and if we can display the requirements to the player through UI (if he can’t perform an action for example), something that pops up for 3 seconds for example, displays it’s message and then disappears, that would be great as well)

Edit: @bixarrio I noticed something a little interesting in the Crafting System. If you’re crafting something that takes a while and decide to close the UI for example and then return, the yellow bar (I changed the color to green in my copy) freezes in its position until you choose another recipe. Yes, this works well, but I was wondering about cases where I want the crafting times to take long for aggressive recipes perhaps (yup, I want to mess with the crafting duration a bit, xD), ones for possibly high level weapons, where the player can walk away from the table for a while, do something else, and then return to claim his weapon a while later… how do we go around this? To get the crafting to continue, even if the UI is closed?

TLDR: I want my crafting to (optional function for now, so we might need to use a bool for that in the recipe itself. We can name it something like ‘craftWhenPlayerIsGone’ as a wild guess) continue even if the UI is closed by the player, for recipes that’ll take a longer time (how we split the XP for those longer recipes and their ingredients is still something I’m thinking of)

I have created a branch in the repo with the required changes to have recipes that need the player to be on a specific level to craft. As for a full skills system, that’s something completely separate. Here, we just add a required level to a recipe (0 is the default so it’s always craftable) and if the player is not at that level yet, they can’t craft the recipe

image

The branch is here

I know about the bar still being there when you leave mid-craft, I just haven’t fixed it yet.

The crafting being cancelled when you leave is by design. I have been thinking about this but managing long crafts is a different monster. A player can leave the scene, and then that crafting table is no longer loaded. So I have to build some system that will keep track of everything. I may look into it, but it’s a little more complex than just straight forward crafting.

There are two options for this:

  1. Do it like Minecraft where the table stops crafting when it unloads and resumes when it loads again. This means the table is only crafting when it is loaded. It’s a little simpler, but still requires a bunch of tracking, or
  2. Do it like Valheim where the table ‘continues to craft’ even if it’s not loaded. It really just keeps track of where it is in the crafting process and when it loads again, it determines how much crafting would have happened during the time it wasn’t loaded and adjusts to cater for that. Not rocket science, but still a bunch of tracking that needs to happen

In both cases I would have to move the crafting process from the UI to - probably - the crafting table itself (which I should have done from the start anyway).
I will also change the way crafting works for this. Currently, you press craft and the ingredients are only removed from your inventory when the crafting completes. For a long craft like this, the ingredients will be removed immediately.

I will look into this but it may take a little while. I also have to work and there may be things that come up that I’m not thinking of right now.

I think we can try with this one, it sounds a little more natural. In the end, we can have an NPC that pretends to be doing all the crafting for us while we’re gone, for those ferrocious Crafting tasks of crafting the superior weapons later down the line in-game (probably not a boolean anymore, but let’s keep that option open as well :slight_smile: ).

If we’re going down this route as well, we may also add a timer on the UI on the top right hand corner, something for the player to know when their products will be ready. So now we have a filler (which needs a tiny bit of fixing) and a timer, for when the time is too long (and an increment/decrement button, something for the users to increase the quantity they need… I’d be lying if I said this wasn’t an idea that came from the top of my head out of nowhere (time for me to be quiet for a bit))

And regarding the skill tree, I understand this might be a major task, but I’m genuinely curious on how this would work, if we get to working on it.

Completely understandable :slight_smile: (please take the time you need)

I imported the new package, but was unclear on where the new Crafting UI, with the levelling system integrated, is… Can’t find that in the Recipes Scriptable Object or the Crafting UI either :sweat_smile:

There is no new package. Just the changes in the repo

I had a brief look at this (I am also leaning towards the Valheim way) and it is going to require a complete overhaul of the crafting system. I will attack this tonight and see what I can come up with. Will probably be changing the whole system into a MVC pattern. Again, I should have done this from the start.

Yup, I downloaded that. But… Can’t find any changes in the ‘Crafting UI’ prefab, or anywhere in the imported Crafting system that addresses these changes.

I secretly got excited reading this lel…


Edit
I made a v0.2 package with the changes

Alright so the previous version had an empty slot for the requirement level TMPro UGUI, but it was missing. I created my own and got it to work. Apart from that, this system works quite well (if I bump into any weird bugs, I’ll update you), but I still hope we can have a skill tree dedicated for crafting, smithing, woodcutting, mining, fishing, etc (I coded a simple woodcutting and mining system on my own, I don’t mind sharing it)… I’ll probs come up with an entire skillset for an RPG-Style game for different needs. I have strong belief it will want to make the player play the game more, because now he has different skills to train. @bixarrio and @brian_trotter thank you both so so much for carrying me this far with my wild project ideas… :sweat_smile: (I’m not gone yet, but a simple thank you and appreciation might be nice from my behalf, at least for the moment :laughing:!)

Frankly speaking though @bixarrio , your code is very very clean, and this makes it very easy to understand what’s going on

BTW if anyone reading this needs the code to get the Player to get close to the crafting table first, replace your ‘HandleRaycast()’ method with this one:

public bool HandleRaycast(PlayerController callingController)
        {

            // If there are no recipes, no interaction with the crafting table allowed
            if (recipes == null || recipes.Length == 0) return false;

            if (Input.GetMouseButtonDown(0))
            {

                // Distance between the Players' Calling controller (i.e: the player), and the Crafting table position
                float distanceToCraftingTable = Vector3.Distance(transform.position, callingController.transform.position);

                if (distanceToCraftingTable > acceptanceRadius)
                {

                    // If you are far from the table, move towards it first
                    callingController.GetComponent<Mover>().MoveTo(transform.position, 1.0f);
                    isMovingTowardsCraftingTable = true;

                    // If you are moving towards the table and you're close to it, don't get closer, start crafting
                    if (isMovingTowardsCraftingTable && distanceToCraftingTable <= acceptanceRadius)
                    {

                        isMovingTowardsCraftingTable = false;
                        CraftingActivated?.Invoke(recipes);

                    }

                    return true;

                }

                else if (distanceToCraftingTable <= acceptanceRadius)
                {

                    // If you're close to the table, start crafting, don't get any closer
                    CraftingActivated?.Invoke(recipes);
                    isMovingTowardsCraftingTable = false;
                    return true;

                }

            }

            if (isMovingTowardsCraftingTable && Vector3.Distance(transform.position, callingController.transform.position) <= acceptanceRadius)
            {

                // If you're close, start crafting. Don't get any closer
                CraftingActivated?.Invoke(recipes);
                isMovingTowardsCraftingTable = false;
                return true;


            }

            return true;

        }

It’s a tad bit sloppy, where you need to move your mouse around a bit when you arrive to get it to work, but I’m still trying to fine tune it to get it to work properly

And add these two new variables:

// Accepted distance from Crafting table:
        private float acceptanceRadius;

        // Is the player moving towards the crafting table...?
        private bool isMovingTowardsCraftingTable = false;

and if needed, initialize your ‘acceptanceRadius’ variable in your ‘Awake()’ method as follows:

void Awake() {

acceptanceRadius = 3.0f;

}

Edit: @Brian_Trotter can we please have this section re-opened? It got shut down before we finish it off :sweat_smile:

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms