Тёмный

Custom Resources in Godot 4 and How to use them 

Unain
Подписаться 2,4 тыс.
Просмотров 12 тыс.
50% 1

Опубликовано:

 

14 окт 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 54   
@HakanBacon
@HakanBacon 6 месяцев назад
Wonderful tutorial! Straight to the point with examples and visuals. Lovely work
@stabbedbyapanda
@stabbedbyapanda 2 месяца назад
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!
@Bloom_HD
@Bloom_HD 6 месяцев назад
Very good visuals and explanation. Thank you so much!
@chuman71
@chuman71 7 месяцев назад
Best video on custom resources for Godot 4.x I found so far! thanks!
@qooldeluxx
@qooldeluxx 8 месяцев назад
great job, hope to see more godot 4 tutorials, you did a great job explaining.
@oreofilledjoy302
@oreofilledjoy302 5 месяцев назад
Thank you! I've been searching everywhere for a way to load my RPG Job stats!
@brendanhall3181
@brendanhall3181 4 месяца назад
Best introduction to resources I've found!
@Marco-L
@Marco-L 8 месяцев назад
Very nice explanation. Thank you very much.
@isaacdobson8760
@isaacdobson8760 23 дня назад
you have a wonderful voice
@alaouiamine3835
@alaouiamine3835 5 месяцев назад
Thank you for the clear tutorial
@Zlorak
@Zlorak 5 месяцев назад
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?
@Unain
@Unain 5 месяцев назад
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 :)
@Zlorak
@Zlorak 5 месяцев назад
@@Unain Tysm! I'll def watch it, i was looking for a resource like that one.
@b.c.a683
@b.c.a683 4 месяца назад
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 ?
@Evilprince191
@Evilprince191 4 месяца назад
Great tutorial 😊 May i ask why at 7:02 you load the resource in your method instead of preloading it as export variable like the player scene ?
@Unain
@Unain 4 месяца назад
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 :).
@limodemh5468
@limodemh5468 7 месяцев назад
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?
@UndeadMunchies
@UndeadMunchies 2 месяца назад
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?
@Peak_Stone
@Peak_Stone 23 дня назад
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
@danielhalond6292
@danielhalond6292 6 месяцев назад
great stuff! thanks!
@rremnar
@rremnar Месяц назад
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.
@young_leosia_fan
@young_leosia_fan День назад
Why for windows specifically?
@mkjyt1
@mkjyt1 6 месяцев назад
Thank you!
@alexnoman1498
@alexnoman1498 8 месяцев назад
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?
@Unain
@Unain 8 месяцев назад
Sounds feasible. Could maybe look at Brotato and see how they handle modding since that's made in Godot.
@randomguy0071
@randomguy0071 Месяц назад
what's the difference between scene and packedscene?
@HurricaneSA
@HurricaneSA 8 месяцев назад
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?
@Unain
@Unain 8 месяцев назад
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?
@HurricaneSA
@HurricaneSA 8 месяцев назад
@@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?
@Unain
@Unain 8 месяцев назад
@@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 :).
@HurricaneSA
@HurricaneSA 8 месяцев назад
@@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.
@Unain
@Unain 8 месяцев назад
@@HurricaneSA No worries, glad it worked out for you :)
@willirittmann1917
@willirittmann1917 4 месяца назад
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
@agriasoaks6721
@agriasoaks6721 3 месяца назад
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?
@stabbedbyapanda
@stabbedbyapanda 2 месяца назад
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
@agriasoaks6721
@agriasoaks6721 2 месяца назад
@@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
@stabbedbyapanda
@stabbedbyapanda 2 месяца назад
@@agriasoaks6721 oh I think that's a case of using signals. Or creating a var reference to specific classes
@agriasoaks6721
@agriasoaks6721 2 месяца назад
@@stabbedbyapanda Well in that case, could you give an example of how to use signal to communicate between custom resource .tres files please?
@stabbedbyapanda
@stabbedbyapanda 2 месяца назад
@@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.
@gimgiringim4002
@gimgiringim4002 6 месяцев назад
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?
@davids5195
@davids5195 5 месяцев назад
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
@ICSkill101
@ICSkill101 4 месяца назад
I get an error: Invalid get index 'Starting_Health' (on base: 'Nil'). Why so?
@lcdcstudios
@lcdcstudios 3 месяца назад
idk if you are still experiencing a problem but you might want to export your var stats: characterstats in your player character
@ICSkill101
@ICSkill101 3 месяца назад
I solved the problem, don't remeber how.
@pixobit5882
@pixobit5882 7 месяцев назад
How did you animate the video?
@Unain
@Unain 7 месяцев назад
motioncanvas.io/
@pixobit5882
@pixobit5882 7 месяцев назад
​@@Unaini knew it :D
@shadowman_93
@shadowman_93 4 месяца назад
you should better stop whistling while talking xD Thanks for the great video!
@gustavo3220
@gustavo3220 5 месяцев назад
Rechourches 😂😂😂
@claytonmurray4328
@claytonmurray4328 8 месяцев назад
😬 'promosm'
Далее
When to Use a Resource Over a Dictionary?
11:06
Просмотров 8 тыс.
КТО БОИТСЯ КЛОУНОВ?? #shorts
00:20
Просмотров 488 тыс.
Programming a tactical strategy game in Godot 4
14:50
How Games Make VFX (Demonstrated in Godot 4)
5:46
Просмотров 350 тыс.
Godot Scripts I add to Every Game
12:34
Просмотров 26 тыс.
PirateSoftware Breaks Down CrowdStrike Computer Issue
12:56
Godot Debugging Techniques EVERY Dev Should Know
16:23
How One Line of Code Almost Blew Up the Internet
13:47
State machines and state charts in Godot
24:11
Просмотров 72 тыс.