Thank you, i've watched 4 explanations on Resources, but this one made it the clearest. One thing I'm still struggling to understand is what functions i should contain in a resource vs in the scene script. Still mulling that one over. Ahhh a fellow Unreal dev to Godot!
Excellent tutorial, helped me a lot to understand Resources! - I do have one question. I'm working on a RPG card game, where each card has a name, a description, and an effect as a function. It seems like you cannot save functions inside .tres so I guess the right way to save each card would be a scene each?
You would have one scene that you fill with the information from the card resource. So the texture/description/name you can just get from the resource and load into that scene. For specific card effects I would have a separate node that you can attach to the card which handles the effect. I would recommend checking out: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-iLT6pTluYvw.html who is making a Slay The Spire like game to see how he handles the cards :)
Thank you , Really like your way. I'm new on godot , I have a question : so resources can be used for creating all the items in the game and saved in that data container whenever needed we can call or already loaded in game. for example I got different type , textures ,and stats of 50 swords , 50 maces and 50 spears so should I have a 150 different files under weapon_resources ?
Around 7:19 I explain why. We can't preload dynamically created paths, because the program doesn't know on compile time what the string is going to contain :).
Thanks for the explanation! Only if something could explain Resources is like using json to save the information let's say for the characters? So this is godot's way?
I suppose I understand how they work now. I just am struggling to understand *why* you would use them. Everything shown here does not need a resource to do in any way, and if anything is made more complicated by using them. What is a use case where a resource is the clear option over just extending off of a custom class or using a script template?
From what I understand, it reduces references and dependencies and helps in error tracking. if there is a bug, you can to ognore respurces as they are inert. if however all your variables are stored in scripts, then you jave to reason about them not the best answer. but its the best i can do
I always thought resource files were a compiled construct for a type of object for the Windows OS. Perhaps it's different for Godot? Regardless, this is a good tutorial, thanks.
I heard you can load more of these Resources dynamically. This allows for content updates or mods. I now want to figure out how to ship a modding Godot project that allows the creation of these resources, packaging them into a blob that my game understands. Then having the resource loader, UI, and game deal with any amount or a selected subset of all available resources. If I had that, I could just ship the game with all default gameplay and assets as the default "mod". Does that sound feasible or sensible? Would any part of that make for a good tutorial video?
Hi. Let's say you want to use a resource file to spawn an item scene. In the resource file you have a field for the packed scene and type PackedScene so you can easily drop a scene in the resource file when creating the resources. Now you want to know what the item is when it's spawned so you attach the resource script to your item scene and add the item resource file in the relevant field. Except you now run into recursion because you're loading the item scene into the same item scene. Of course it's a simple fix. One can simply add a scene path to the resource file instead of reference to the scene. My question is this - Is there a way to do the above without triggering recursion? Like is there a way to not load the packed scene in the resource file when attaching it to a script in its own scene? Or is scene paths the only option?
I wouldn't have the whole item scene in the resource file. The resource file has a name, texture/3d model and other properties. You can just have an Item scene that you can spawn with the resource file as property. The Item scene will set its own properties (texture/3d model) based on the resource file on spawn. But it sounds to me like you want to have the item be a pickup and be something you can use at the same time. Its better to split them up. What are you trying to do exactly?
@@Unain Let's say you have multiple containers in your main scene that each spawn a weapon. Attached to the container scene is a script that has an "@export weapon_resource : WeaponResource". So for each instance of the container you simply drag the relevant resource file to the Weapon Resource field in the inspector. When the player activates a container it then looks at the attached resource file and spawns the correct weapon. Inside the resource file is a PackedScene field that holds the specific weapon scene that needs to be loaded. Doing it like that works fine but then you need the player to know what type of weapon they just picked up. So you attach add a "@export weapon_resource : WeaponResource" to your weapon scripts to easily check the weapon information. Except, you can't do that because Godot tries to instantiate the PackedScene instead of just keeping a reference. So you get infinite recursion because obviously the gun scene is going to load itself into itself forever because it keeps wanting to instantiate whatever PackedScene is in it's resource file. Now the solution is to simply use a path to the scene instead of the actual PackedScene which is fine but it would be nice if one could simple drag the relevant weapon scene onto the PackedScene field instead of having to copy paths for 50 different weapons. So yeah, I was just curious if there's a easier/better way to do this?
@@HurricaneSA Aha, well what I would do is have a weapon_pickup_resource that has the packedscene in it (if the container only has to know the weapon to spawn). No packedscene in the weapon_resource itself. Then you can just put the weapon_resource in your weapon script. When you pick it up the weapon_pickup_resource will spawn the weapon with weapon_resource. It would mean you have to make a weapon_pickup_resource for each weapon as well though, but you can put extra information in that resource, like: special pickup sound/inventory sprite/texture/etc. This is me just spitballing, because I don't know how your weapon system is set up :).
@@Unain I'm so stupid. After taking a break I came back to realize it was entirely unnecessary to use a resource file just to spawn a weapon, thanks to your input. So instead of making it complicated I just changed the "@export weapon_resource : WeaponResource" in the container script to "export weapon_scene" : PackedScene" scene. The weapon resource file now only contains information about the weapon and not any scenes and stuff. So container spawns scene, scene has resource file with all the data and everything works as it should. No need to worry about paths and stuff anymore. Sometimes one can really miss the obvious. Lesson learned anyway. Use resource files to store data only.
Dont know for you guys, but for me the export variables resets too often and lose its reference, im trying to use export only for debug things or smples stuffs that i can easily redo
In nested custom resource, is it possible for the child (I'm not sure if I'm using the term correctly) resource to get the property of its parent's property?
If you are saying something like BaseSkillResource -> FireSkillResource -> FireballSkillResource. It should be able to, i haven't tested it but i don't see why it wouldn't. You should be able to test it real quick, by just making a function to print something when called in the grandparent
@@stabbedbyapanda No no no, It's more like Skill resource that has a property called effect (array) that holds another custom resource class called SkillEffect. I wonder if this SkillEffect can access the property of the Skill class where it is in
@@agriasoaks6721 Sorry I can't i'm also learning about resources. You may not be able to communicate between resources with signals either the more i think about it, you will just have to test :/ If it doesn't work my recommendation would be to have a scene that loads your resources and then you can reference them together. (I think) This would act as a manager that handles what you want.
Hi, I keep getting the error that add_child cannot be called on a null instance when using 2D nodes instead of the 3D versions. Is there any way you could help me with that?
I'm getting a similar error for 2D nodes. For me, it's with the instantiate part. "Cannot call method 'instantiate' on a null value," it says. Never mind. I figured out my issue. I had the @export var for the PackedScene, but I had forgotten to put the desires scene into the editor. So, of course it was a null value, lol