PLEASE just use CASTING

Sdílet
Vložit
  • čas přidán 4. 06. 2024
  • For 70% off + 3 months free NordVPN here : nordvpn.sjv.io/TCG
    Casting is... a problem, but not as big a problem as people often seem to think. For sure, you need to be aware of the issues with it but blindly avoiding casting is just straight up wasting your time. So let's talk about that.
    Join the discord for any help you need! : / discord
    Join this channel to get access to perks:
    / @thegamedevcave
    support the channel and development over on patreon : / thegamingcaves
    Get personalized Coaching : www.fiverr.com/s/2P9GaN
  • Věda a technologie

Komentáře • 124

  • @thegamedevcave
    @thegamedevcave  Před 29 dny

    For 70% off + 3 months free NordVPN here : nordvpn.sjv.io/TCG

  • @GreyManFaustus
    @GreyManFaustus Před 29 dny +30

    I feel like these videos on how engine functionality actually works are an incredibly valuable thing. There's so much cryptic half-information and guesswork out there that getting a coherent understanding by yourself is a pretty laborious task.

    • @JaredWyns
      @JaredWyns Před 29 dny +2

      You are 100% correct as it is quite laborous but the returned value is exponential compared to the applied effort. Understanding if things are possible or better put, scalable or if there might be more unknowns preventing success (such as needing double floating point back on UE4) are worth their weight in gold. It's one thing to waste a bit of time as shown in the video by doing extra interface stuff, but another matter entirely to have to rebuild a feature all over again after determining a roadblock with the engine in one way or another due to incorrect expectations of how something works. It's an invaluable skill that often comes with more and more experience and bigger projects & the concept applies to any software really

    • @arnaudkaho7137
      @arnaudkaho7137 Před 28 dny

      It's open source mate, free to look into it.

    • @GreyManFaustus
      @GreyManFaustus Před 28 dny

      @@arnaudkaho7137 because someone watching tutorial content mainly targeted at hobbyists/beginners will most definitely know how to look into engine code and be able to understand it.

    • @nubunto
      @nubunto Před 23 dny

      source available*

    • @arnaudkaho7137
      @arnaudkaho7137 Před 23 dny

      @@nubunto 🤔

  • @zoravibes
    @zoravibes Před 24 dny +9

    A good analogy could be like when you tell children to stay away from fire. Fire can be very dangerous when handled improperly, and children are just too inexperienced to explain, and be expected to retain, when it's safe and when it's not safe to use it. So to avoid any chance of it becoming a hazard, you warn them to stay away from it completely. Which is why I get why people say to avoid casting. But like fire definitely has its uses, there are many many uses for casting, and eventually you'll mature enough to understand how to be responsible with it.

  • @AmorVim
    @AmorVim Před 29 dny +14

    I wanted to throw my hat into the ring as well, but decided not to. Casting is indeed fine, issue arises when you cast to things not loaded in memory. So if that is an issue, you can circumvent this by casting to base classes instead, which you can setup with the basic skeleton functionality you want, drastically reducing the potential spike in memory used.
    I used to do interfaces all the time for literally everything, then I realized I was adding unnecessary overhead to the program. Interfaces are good for when you want to share functionality in different classes. It took me a while to realize this, and I only figured this out when I started using the C++ side. A tool is only as good as how it is used. Sometimes casting is better, sometimes interfaces are better. Interfaces can add unnecessary complexity to your code if used incorrectly, which I have done a lot. This is ignoring that under the hood, calling an interface function results in a cast anyway. So if casting is bad, then so are interfaces.
    As a general rule, if it's only ever going to be one class, use inheritance to your advantage and cast, if you are going to use different unrelated classes (for whatever reason) use interfaces.
    That said I still like using interfaces, if I think there might be future use for it. The cost is generally low either way if used correctly.

    • @thegamedevcave
      @thegamedevcave  Před 29 dny +2

      i think this is pretty much spot on. casting is fine, but shouldn't be a crutch in situations where it noticeable harms performance. it's 1 tool in a wide toolbelt that has it's own usefulness within it's own context.
      in general overdoing interfaces will do less harm than overdoing casting so i get that a lot of people want to be on the safe side and avoid casts altogether. I personally think "X is bad" should be a mindset that we avoid, "X is bad at Y and shouldn't be used for Z because of that" is good though. :)

    • @rgmattson
      @rgmattson Před 28 dny +2

      Came here to post the same thing. To put a fine point on it: avoid casting against blueprints, which will always load every part of the blueprint into memory if it isn't already, which is why casting against base classes is the right way to go. (Source: I was casting against an NPC BP once and absolutely wrecked perf on debug builds of the editor.)

  • @lecastlevania
    @lecastlevania Před 29 dny +2

    Thanks for clarifying this topic and for sharing!

  • @jdrewlayton
    @jdrewlayton Před 25 dny

    So refreshing to get real explanations. Your videos have helped me understand so many things in the engine from “why” instead of just “how.” More of these please!

  • @pterafier
    @pterafier Před 29 dny +1

    Is there any documentation you sourced this from? Would love to read more about it

    • @thegamedevcave
      @thegamedevcave  Před 28 dny +2

      sadly unreal's learning materials and documentation kind of suck.
      what i did to double check if this is all correct is look at how things work in c++. With that you need to add a #include to a class in order to cast to it. that's pretty much what the casting node seems to do too, when it exists in a blueprint, it just adds a #include to that class. So if you want to read up more about that I guess that's a place to look, how #include works and what it actually does.

  • @Fighter05
    @Fighter05 Před 17 dny +1

    There are reasons it exists; reasons Epic actually put it in the Engine. Every project ever, has casting to some degree.
    The problems are way less pronounced today. By 2025 ish, its predicted the majority of PC consumers will have at least 32 gigs of ram. Consoles already have 32+ gigs of ram. Its extremely hard for an indie to work at a scale where the pitfalls of casting will actually apply.
    When you work on large projects that have asset linkers, Data Assets like DA_CharacterAudio or a game like Fortnite, literally thousands of potential skeletal mesh skins. You need ways to load assets in and out without referencing the entire asset tree.
    Incorrect Casting there will literally prevent most players from being able to play due to lack of memory or ungodly load times with linking like 10 gigs of audio directly to a player character needlessly.
    But you are right. For most people? Most devs? Most projects? What they are Casting to will already exist in their game anyway. Its already loaded and therefore has virtually zero cost. Casting can also prevent hitching common in a lot of titles by just hard linking related gameplay assets.

    • @thegamedevcave
      @thegamedevcave  Před 17 dny

      oh for sure! dont just randomly cast to a bunch of stuff without knowing that it also loads in a bunch of assets.
      and even though i'm advacating for using a cast every now and then, i still think setting up an interface call makes more since 9/10. people are just unreasonably affraid of casting and don't actually make any consideration for it as a result.as you say, for most people, they're working on a scale where even if they do mess things up, it doesn't actually hurt all that much with modern computers having more and more memory .

  • @TheProloke
    @TheProloke Před 29 dny

    This makes so much sense. Good stuff man

  • @Fizziepop
    @Fizziepop Před 28 dny

    Thanks! This is a great explanation of the topic. Love hearing why and how it all works, rather than following weird rules blindly.

  • @pimeine
    @pimeine Před 24 dny

    Thank you for that video!

  • @1_Man_Media
    @1_Man_Media Před 29 dny +1

    Solid video, and I agree. Some casts have to happen, like I open loading a level by casting to game_instance which I use as a reference container. There is literally no way to get the GI other than a cast. However, I do try and leap frog references as much as possible to minimize casting but a few casts to get gi, game mode, player char is totally fine.

    • @thegamedevcave
      @thegamedevcave  Před 29 dny +1

      yeah GI is another one that's pretty much a free cast. everything in your game already exists in your game instance, so unless youre casting to a GI class that you're not using which... why would you? youre pretty much free to cast to your GI anytime you want ( i mean, within reason of course xd)

    • @1_Man_Media
      @1_Man_Media Před 29 dny

      @@thegamedevcave Ya, you can't even change GI mid game not sure why you would ever have 2.

  • @Flowerpot2905
    @Flowerpot2905 Před 17 dny

    Very clear explanation - thank you.

  • @TheFlyingEpergne
    @TheFlyingEpergne Před 29 dny +12

    literally just went through a huge decoupling process and at the end of it all i realised i could have just casted in so many places as many things were already loaded a lot of the time e.g player controller, player character, game mode etc

    • @thegamedevcave
      @thegamedevcave  Před 29 dny +4

      oof that is painful XD but hey, it's better to know HOW to decouple things than not know how to do it at least, so that's an upside :)
      but yeah sometimes a quick and dirty cast will save you your sanity and not actually cost anything XD

    • @ryanjdevlin87
      @ryanjdevlin87 Před 29 dny +2

      Yes sadly because of misinformation its easy to not realize that EVERYTHING in your level is in memory already... The ONLY things u dont want hard refrenced is things that are not always in the level or in every level. If you have a 1 player character game with 1 Level you can litterally hard ref everything otherwise you need to use soft refs and plan accordingly

  • @angolodiappla
    @angolodiappla Před 29 dny

    Hi, can you make a video for using hand ik to "grab an item" at a dynamic location? (Like, the hand automatically stretches and aims at the item regardless of the position)
    Thanks

  • @italocassini
    @italocassini Před 25 dny

    Very nice video!
    I've always had this feeling casting is being injustice in some situations.

  • @TvCinemaCraft
    @TvCinemaCraft Před 28 dny

    thank you

  • @mahkhardy8588
    @mahkhardy8588 Před 29 dny +4

    I hope beginners find your videos before others because man, the guys that rank when searching back when I watched tutorials, looking back now, are the worst.

    • @TheFlyingEpergne
      @TheFlyingEpergne Před 29 dny

      matt assbland and gorka games in particular are literally "how to ue5 worst practice"

  • @Eagle6Airsoft
    @Eagle6Airsoft Před 29 dny

    You can run a check / graph to see how heavy the load for casting is. I can’t remember it off the top of my head, but it will show exact memory usage of all the references you are calling with the cast. If you get a lot of nested ones it can be expensive. I imagine it’s more important later on with regards optimisation, I still think interface is the way to go.

  • @SkribblerStudios
    @SkribblerStudios Před 28 dny

    thanks!

  • @suave2111
    @suave2111 Před 28 dny

    This is really useful info! I have a lot of experience in other engines and found myself trying to avoid casting in Unreal just because I had seen other people say it. I went as far as starting to cache references in other classes to avoid having to cast again later and now I'm realizing that has memory implications, oops. Definitely going to be diving into the rest of your videos!

  • @arrowsdev
    @arrowsdev Před 29 dny

    this video is GOLD

  • @florethebrave
    @florethebrave Před 2 dny

    I like how I just watched a video from your channel called "STOP casting!"

    • @thegamedevcave
      @thegamedevcave  Před 2 dny +1

      both sides of the arguments are important to hear, you need to learn about why casting is bad, but also that you can use it when it makes sense.
      too many people learn about the downsides of casting and go into a "NEVER EVER CAST EVEN IF MY LUIFE DEPENDS ON IT" mindset, which is way too far in the other direction XD

  • @tijmdevries2222
    @tijmdevries2222 Před 29 dny

    Thanks for this video. This will save me a lot of time. I'm just wondering about something. Does a cast reload a class into memory if it's already loaded. I'm hesitated to use casts in functions that will be used many times like in behaviour trees because of the compute effort needed to reload it.🤔

    • @thegamedevcave
      @thegamedevcave  Před 29 dny +1

      the cast itself on execution doesn't load anything, it is the existence of the node in the first place that loads in the other class. which is the tricky but. even if you have a casting node somewhere in your blueprint that rarely gets triggered, that other class is still being loaded in the moment you spawn in the actor that does the casting.
      I believe it's even so bad that a casting node that's disconnected from anything will load other classes in. But once that's all loaded in, the actual execution of the cast node is.. well not free of course, limiting any unneeded repeating of code is probably a good thing, but it's not really something to worry about with the cast node.

    • @tijmdevries2222
      @tijmdevries2222 Před 23 dny

      Thanks for the answer! By the way, are you Dutch? I'm just curious because of the accent 😅

    • @thegamedevcave
      @thegamedevcave  Před 23 dny

      @@tijmdevries2222 yupp!

  • @Chromixxxx
    @Chromixxxx Před 28 dny +1

    I usually cast a reference once at begin play convert it to a variable then i just call from that variable anytime i need it thats been my method atleast

    • @thegamedevcave
      @thegamedevcave  Před 28 dny +2

      While that is better in theory, it doesn’t actually matter that much. The existence of a casting node is what loads other things into memory, not the execution. The existence of a variable will do the exact same.
      That can be fine, just something to be mindful of :)

  • @mademax1
    @mademax1 Před 29 dny

    This is good stuff, hope it helps some devs somewhere

  • @gabrielorellana7962
    @gabrielorellana7962 Před 24 dny

    I thought the dependency of casting is not recommended when it's used to access a class of a general actor/object reference, instead an interface can be used, because it's easier to maintain.
    An example is the magnet ability in Zelda BOTW, when it's activated all metallic objects glow and are selectable. Traditionally, all those objects would be children of the same Metallic Object class, so, when they are selected you need to cast to the parent class. Then let's say Nintendo bought an asset from the marketplace which contains ready to use metallic weapons, but they are not children of the metallic object base class, then, they need to re-write the objects instead of just implementing an interface on them

    • @thegamedevcave
      @thegamedevcave  Před 24 dny +1

      yes, for a lot (by far most) cases setting up your code to use interfaces will both preform well and be easier to scale up in scope.
      Certainly don't throw casts all over the place but if you understand what the actual downsides of a cast are, you can also decide when they are worth using.
      For the example you give here, the player class doesn't need (and shouldnt) to know about every single possible object to interact with so it just uses an interface and lets the object itself figure things out. That way, specific objects can also easily implement their own unique code when interacted with.
      Now instead, let's say we have a weapon and that weapon needs to know some of the player's stats in order to do something (assumeing damage calculation is done on the weapon). there is no real harm in casting from the weapon to the player here, since the weapon is never going to exist without the player and the weapon simply needs to access a variable that exist on the player. Now, that does mean that this weapon now can only be used by the player but if you design your code with a bit of forsight, you probably would have a parent class "Combatcharacter" or something like that, which has all the combat related values on it, and you can cast to that instead, now it will also work on any other class that inherits from "CombatCharacter" and there's no real downside to it anymore.
      about 95/100 times interfaces will end up being smoother to work with and better for memory, but those 5/100 times that they're not, it's dine to use a cast if you know when to :)

  • @iamagenius2646
    @iamagenius2646 Před 28 dny

    This gentleman is absolutely right!
    A wonderful easy explanation about why casting is a real feature and it has a reason to exist. It has its benefits and weak points.
    So, yes use casting if you know that object is already loaded ... Game instance for example, always loaded

  • @fazzaricostantino8883
    @fazzaricostantino8883 Před 28 dny

    Substantially do not "Abuse" of it.

  • @Spacemarine658
    @Spacemarine658 Před 22 dny

    😅 i like to keep my memory usage small and my code flexible so my rule is if i need to chain casts or if the thing I'm casting to may not always be loaded ill use interfaces or didpatchers but i think like most thing its a tool you just need to know how to use

    • @thegamedevcave
      @thegamedevcave  Před 22 dny +1

      yeah for sure, dont JUST use casting, people going around telling everyone to avoid casting comes from the issue of people overusing casting and not understanding it.
      It's all about knowing what the impact is of the choice of tool you make :) if that impact is very small and you can use a cast, you should feel free to cast to something. Just have to be careful about it but don't need to entirely avoid it :)

  • @seansopata5121
    @seansopata5121 Před 29 dny +1

    The correct answer is to avoid casting if you can, but use it if you would otherwise need to jump through hoops to not use it. And don't feel bad about it.

  • @ParrotOG
    @ParrotOG Před 26 dny +1

    I've seen so many people use an interface function with an isvalid macro to get a blueprint reference. like bro, you're literally casting with extra steps 😪

  • @ricardo22448
    @ricardo22448 Před 29 dny

    so i guess as a summary use cast when: it is a thing that for example a npc or your character creates anyway and use interface when it is part of the npc but you don't want to load it every time a npc or player spawns. sounds ok?

    • @thegamedevcave
      @thegamedevcave  Před 29 dny +1

      more or less. It's more like knowing what parts of your game always belong together and what parts can also exist seperatly. if they can exist seperate from eachother, use things like itnerfaces toprevent hard referencing. if they always exist together anyway, cast as much as you'd like to those things. (which is why casting to the player class 99/100 times is fine because the player is always loaded anyway, since.. well, it's the player).
      if the NPC you're talking about is an enemy that appears once in your game, definitely prevent hard references, but if it is a 2ndary character that's always with he player ( like sonic and tails in the old sonic games), you're safe to cast.

    • @ricardo22448
      @ricardo22448 Před 29 dny

      Thank you!!

  • @MonsterJuiced
    @MonsterJuiced Před 29 dny

    So to clarify, to save time or if there's no other option then use casting if both 'objects' are loaded into the level anyway. Such as actors in the level, game mode, level blueprint etc..
    And that 'get actor of class' is the same cost as casting.
    I've been using interfaces in pretty much every situation I can but I came across a time I absolutely needed to cast to then use my interface to carry across variable data. Odd situation but it worked lol

    • @thegamedevcave
      @thegamedevcave  Před 28 dny +1

      Pretty much, get actor of class has the same memory implications as a cast (so does simply having a reference variable of that type) but get actor of class also is rather expensive to execute on top of that.

    • @MonsterJuiced
      @MonsterJuiced Před 28 dny

      @thegamedevcave so get actor of class is more costly than casting? Might have to rethink some of my code...

    • @thegamedevcave
      @thegamedevcave  Před 28 dny +1

      @@MonsterJuiced yeah by a pretty significant amount, what it does ( more or less) is try all actors 1 by 1 to see if they're of that class ( so, casting pretty much) and once it has found one it returns a reference to that.
      it still creates the hard reference that is the main issues with casting to begin with, but also takes up computing power to find an actor in the first place. it's not as bad as "get all actors of class" that one is even more expensive but it's still not something you'll want to be doing often or on a large scale.

  • @Kagashimin
    @Kagashimin Před 28 dny

    Funny how I just got recommended a video warning exactly against casting and to use something else that I forgot the name of. To be fair, it is a bit suspicious that so many tutorials just do casting.

    • @thegamedevcave
      @thegamedevcave  Před 28 dny +1

      probably wanted you to use interfaces. which is a good tool to have, it's so much more useful in many cases! But it's not a 100% replacement for casting at all times :) sometimes a cast is straight up okay to use :) ... just dont go casting to everything all the time

  • @slackamacgaming6721
    @slackamacgaming6721 Před 28 dny

    Yeah i cast...never had a problem with it so far...

  • @brokenhdd9291
    @brokenhdd9291 Před 28 dny

    I am a professional game developer working in Unreal for a decade, and I FULLY endorse the message.
    All points are spot on.

  • @domthedominator4761
    @domthedominator4761 Před 29 dny

    holly cow i feel like im not insane anymore ever since i started using unreal i was always like why the heck do people hate casting its so quick and easy and doesn't affect performance that bad unless you are using it on each tick so i finally feel like im not insane for thinking this

    • @thegamedevcave
      @thegamedevcave  Před 29 dny

      the cost isnt' actually based on how often you run the casting node, throwing it in tick (while needlessly re-running the cast, which is of course not great) won't actually effect you a lot. the existence of the casting node in the first place is what is (or rather, what can be) expensive due to it creating hard references and loading a bunch of stuff into memory that may not be needed in memory at that time.
      If youre casting to things that are already loaded ( they exist in the level already or are loaded due to hard references by other actors), the main issue with casting isn't actually an issue.
      it's a pretty tricky thing sometimes to figure out when a cast is or isn't okay because of all that, a lot of people just go "well casting is bad. end of story" because of that.

  • @Soraphis91
    @Soraphis91 Před 29 dny

    If I would have to put it into a rule of thumb: "if you have multiple casting nodes in an if/else manner, casting might not be the best tool to use".

    • @thegamedevcave
      @thegamedevcave  Před 29 dny

      oh there for sure, you should 100% use an interface. not just for performance reasons either in that case. in these situations it's legit more painful to stack a whole bunch of casts. just sending out an interface message is so much easier when you find yourself doing that :)

  • @hanswannop9541
    @hanswannop9541 Před 28 dny

    "PLEASE just use CASTING" on it's own is bad advice, if it's the only take away people get from this that isn't great. That said this video is actually a pretty good description of how and when to use casting 👍. Two things worth noting:
    - Re: 9:45. This is true but somewhat misses the point. Assuming you already have a reference to something that you wish to cast to an enemy, an interface eg IDamagable on the enemy will allow you to directly call interface functions on it regardless of its class, in many cases this is preferable as it simplifies shared functionality across different Actors (maybe enemies and players are both damagable despite having different parent classes).
    - Casting to parent CPP classes is pretty much free and does not cause a hard reference.

    • @thegamedevcave
      @thegamedevcave  Před 28 dny +1

      yeah, no single sentence will be able to really show the nuances of when casting is a good thing vs a bad thing. If someone sees just the title of this video and goes off that... well, let's just say that shows a deeper issue in their learning methods XD
      9:45 though, youre' right. my point here is that people want to avoid casting so much, they come up with a bunch of weird ways to not use the casting node, which end up resulting with still having a hard reference, and weird and messy code on top of that too. (Ie : an interface that returns a reference to said object type, that's just a bad idea). those "solutions" are born from a lack of understanding about what makes casting so bad, people just try to avoid using it because they heard they should, without knowing why.
      Having seen that happen a fair amount is what prompted me to make this vide in the first place :)
      small note about the cpp parent class thing : it's not so much that casting to a cpp class is free, more that casting to a shared parent class is free (so a character getting an actor ref and casting it to a pawn is free). but if you have a class that's made in cpp that branches off from actor (let's say something like AItemPickup, which then has a bunch of child classes of it's own, but ACharacter is entirely separate from that inheritance branch), casting to it isn't free just because it is a cpp class. I am sure you yourself understand that! Just pointing it out in case anyone else reads this and misunderstands your meaning :)

    • @hanswannop9541
      @hanswannop9541 Před 27 dny

      @@thegamedevcave Sure, I understand these kind of titles attract an audience and hopefully people are interested enough to listen carefully to your advice. I understand the point you were trying to make about avoiding interfaces, I've also seen the case you mention where people try to avoid a cast an end up with a hard ref anyway because it took a bp as a param or returned one.
      There really is a difference between casting to a cpp base and a bp though. BPs are assets and as such will require any hard referenced assets be loaded (as you've mentioned). Cpp classes are *not* assets, casting to one or using functions defined in one will not in and of itself cause any other assets to be loaded at the same time as the calling/casting BP. The cast itself to a cpp class is so low cost that ive never seen it have a noticable performance impact. Avoiding asset dependency hell is the primary reason I and many others do tend to stear people away from casting to BPs. It can have very real load performance, memory and compilation time costs.
      As youve mentioned there are circumstances where it isnt so bad such as casting to assets that you expect to already be loaded, or within a small group of highly coupled bps.The advice I tend to give where I work is if you want to cast, do it to the highest parent class that gives you the functionality you need, and if at all possible that parent should be in Cpp. If someone is getting their feet wet, prototyping or building something small most of this advice is moot, cast away! Just know that there are reasons it sometimes gets frowned upon (that it sounds like you are already well aware of).
      If anyone is curious to learn more there is a great talk from Sjoerd de Jong here that covers this topic really well.
      czcams.com/video/0YMS2wnykbc/video.html
      Edited for typos and to correct above link :)

    • @thegamedevcave
      @thegamedevcave  Před 27 dny +1

      @@hanswannop9541 yeah for sure! blueprints tend to have hard refs to assets. My point was more that that is due to how they are used and not anything inherit about it being a blueprint. but in particle terms you're 100% right. The point of a blueprint is to setup up a class as an asset that's ready for use. But unlike engines like Unity, where you have prefabs, the blueprint itself also is a class, which can lead to this sort of confusion (but also can be amazing since you can add a little extra scripting to a specific blueprint class of course).
      and yeah, i'm not happy about having to use hyperbolic creaming titles either to be honest. if people would click on video/thumbnails with normal informational content i would much prefer to do that instead. but sadly, you kind of have to trick people into learning sometimes :/

    • @hanswannop9541
      @hanswannop9541 Před 27 dny

      @@thegamedevcave Understood for the titles. Again though a BP acts both as a class (as you mention) but *itself* is an asset which you are making hard ref to if you cast to it. A cpp class is not an asset, this distinction is an an important one when understanding the impact of casting, outside of the valid usage considerations you mention. All the details are in the talk linked. Apologies to be a stickler, its certainly a complex, difficult to teach topic with a lot of *it depends*. Thankyou for your educational work here.

  • @Doubleaa500
    @Doubleaa500 Před 18 dny

    Thats hilarious to imagine every interactible being loaded just because you're playing the game as the main character!! Haha

  • @HyraxGames
    @HyraxGames Před 29 dny +5

    Hear me out
    If you do not not Behaviour Trees, Control Rig, Level BUilding, how to talk to other classes proberly, how to execute events, How to make a proper ui system ect
    DO NOT WORRY ABOUT CASTING!
    Casting is needed, you need to cast sometimes no matter what
    Do not overuse casting but you do need to cast sometimes
    Just make fun games that don't crash, this is more important
    If it runs, It works, it's fun, that's all that matters

    • @thegamedevcave
      @thegamedevcave  Před 29 dny +2

      of course making something fun that works in the most important thing!
      although, most of the things you mention like Behaviour trees, control rig and so on dont directly have all that much to do with casting. the real issues with casting usually come in when casting from 1 type of actor to another type of actor. There it can be relevant to think about when to use and when not to use casting.
      But as long as your game doesn't run like shit and it's fun, nobody cares (or should care) how exactly it is coded! :)

    • @HyraxGames
      @HyraxGames Před 29 dny +1

      ​@@thegamedevcave The point is that
      Whilst yeah, Casting is to communicate between classes
      You have Get actor of class and Interfaces as well...
      Good idea to learn when and when not to use whatever but...
      You need to learn
      How to implement animations, how to make AI, How to make UI, How to modify things, How to build levels Ect ect ect
      If people are too concerned with Casting, they end up having no game... No game is no fun
      So as i said in the past
      If you gotta use 500 casts and 2000 branches... Do that and make a game and get better and better
      100% you'll learn more and more and also do's and don't's

    • @thegamedevcave
      @thegamedevcave  Před 29 dny

      sorry to say but using get actor of class has the same downsides as casting in creating a hard reference to the class but also is very slow to actually preform XD so not really an alternative to casting i'm afraid.
      Your point is valid though, focus on making a fun game first, then focus on learning how to make it optimized when/if needed

    • @HyraxGames
      @HyraxGames Před 29 dny +1

      @@thegamedevcave Yes
      Get actor of class is a slow operation
      Cast to's store a referance within Memory that is const meaning the more you cast the more memory you take up, That is why Epic wrote the note saying "casting can be expensive" meaning Memory will get used
      and if you forget to validity check certain refs this can lead to false allocation of memory on pre allocated addresses and is the reason many Unreal Games actually crashes mainly because the program is trying to allocate something on a pre-occupied memory addresses, so using Validity checks is another thing everyone should learn because it'll ensure you don't run into "I spent two years on my game and do not know how to fix it"
      So i am not saying Get actor of Class is a replacement...
      Not at all
      I mean they have different use cases for different senarioes
      and you should not give a damn if you're a beginner
      You should care about learning as much as you can and have fun in the proccess..:
      The Cast to and C++ vs BP's are usually just because people want views 🤣

  • @Foxedupuk
    @Foxedupuk Před 29 dny +1

    This is the same as the youtubers showing you how to use interfaces and then using them wrong. The amount of misinformation about them is crazy.

    • @TeHzoAr
      @TeHzoAr Před 28 dny

      do you have examples of how they suggest using them wrong? just using them to implement one function/event?

    • @Foxedupuk
      @Foxedupuk Před 28 dny +1

      @@TeHzoAr I have seen lots of examples where the youtuber says that you need to implement the interface on both classes for them to work. I have seen others saying that interfaces are a communication mechanism. I watched one guy the other day go to the trouble of setting up an interface on a blueprint and then just made a direct call to the underlying method when he wanted to use it! I've seen another where an interface is described as "a way of communicating between actors that is basically a function and an event". I could go on

    • @TeHzoAr
      @TeHzoAr Před 28 dny

      @@Foxedupuk the official documentation actually suggests both classes need to implement the interface, it's wild. The only reason I understand them is my c# experience

    • @TeHzoAr
      @TeHzoAr Před 28 dny +1

      @@Foxedupuk like what is going on here in the official docs:
      "Interfaces are useful for allowing communication between different Blueprints. Functions from a single interface can be called on other Blueprints. This can be done when 2 criteria are met:
      Both Blueprints implement the same interface with the required function."

  • @ATomCzech
    @ATomCzech Před 29 dny

    But it will not load whole object including all meshes inside of Blueprint, it load basically just classes, right? Ten I would tell that I should not care about, until it not loading really assents like meshes, animations, textures, etc. If it load just comilet classes with methods, right? But eyes, sometimes even class can be huge, but still not 200 MB character mesh.

    • @thegamedevcave
      @thegamedevcave  Před 29 dny

      if a hard reference loads another class with a hard reference ( like a default value of a mesh, like most blueprints have) then the WHOLE thing gets loaded in. That's also why using soft object references where you can is better (especially to assets like meshes) because then if you do need to load in the class, it won't drag all the other things into memory right away too :)

    • @lennysmileyface
      @lennysmileyface Před 28 dny

      @@indiesigi7807 If you have hard references to assets they will be loaded even if not used.

    • @thegamedevcave
      @thegamedevcave  Před 28 dny

      @@indiesigi7807 casts cost the exact same in blueprint that they do in c++. while in editor, blueprint nodes have a little extra overhead, once compiled into a game, blueprints get translated into c++ classes anyway.
      The cost of a casting node is the need for adding a #include in the c++ class. So, yeah the execution of the cast itself is pretty cheap (not free, but it might as well be). it's the memory of including that other class that is the real cost, which is true in both cases.

    • @ATomCzech
      @ATomCzech Před 28 dny

      @@thegamedevcave This is quite sad. I would really expected that mesh itself will be loaded only if there is required to show it in the level on the screen :-(.

  • @mangarookie
    @mangarookie Před 29 dny

    kasting is baaaaad... mmmkeyy...

  • @flymacseamus3474
    @flymacseamus3474 Před 29 dny

    So you're saying it's perfectly fine to "cast back and forth" within the same character -- but then why even do that, when you can just cast once on Blueprint Initialization, and save into variables all those references you'll need later? Then no more need to cast back and forth and make the BP more complex than it needs to be...
    Unless... is there anything I'm overlooking about storing those references on initialization which in your opinion would make it a problem down the road, or create limitations?

    • @thegamedevcave
      @thegamedevcave  Před 29 dny +1

      the cost of casting isn't running the actual casting node, the thing that makes casting expensive is the fact that you're creating a hard reference to another class/ asset. once that hard reference is in place, running the actual casting node itself is negligible in performance cost. so casting once and saving it as a variable, while better in theory, still doesn't actually save you anything really.
      The point i'm making here is that you can create hard references (most often in the form of casting) between 2 classes that always belong together without is actually costing anything.
      The idea that the execution of the casting node is expensive is a misconception, it's the existence of it in the first place which is (or at least can be) expensive

    • @flymacseamus3474
      @flymacseamus3474 Před 29 dny

      @@thegamedevcave Yeah granted that was a bit besides the point you were trying to make, sorry I think I got stuck on "back and forth" -- I guess if anything, variables help to declutter the BP, even if they don't actually contribute to any perf improvement.
      Although let me ask you a question about casting + storing a class instance reference: if you cast only on BP Initialize, and store that hard reference into a variable, are you storing a "snapshot" of the instance at the time of initialization, or are you indeed saving a reference in the sense that when you access that variable later at runtime, the instance it points to will have been updated by whatever process altered it since initialization?

    • @thegamedevcave
      @thegamedevcave  Před 29 dny

      al object references (blue variables) are pointers, so they just point to an instance and will always reflect it's current state. if you want to "snapshot" something on any actor you need to store whatever info you're trying to snapshot inside a variable of its own ( so if you want to snapshot a float for it's health, you would have another float on whatever actor is doing that snapshot to store that value in)

    • @flymacseamus3474
      @flymacseamus3474 Před 29 dny

      @@thegamedevcave Makes sense, thank you 👍

  • @arnaudkaho7137
    @arnaudkaho7137 Před 28 dny +1

    Learn C++ guys... this is a noobie issue.
    It's all about hard reference, if you don't know that you missed the very first step of programming.

    • @thegamedevcave
      @thegamedevcave  Před 28 dny +1

      everyone is a noobie at some point and needs to be told these things. especially when there is such a common (blind) sentiment to avoid casting without reason in the unreal community :)

    • @arnaudkaho7137
      @arnaudkaho7137 Před 28 dny

      @@thegamedevcave Indeed, i'm just saying it is worth starting with C++ courses because making a significant game will requires a high level of understanding and designing anyway. Things that blueprint never teaches.

    • @thegamedevcave
      @thegamedevcave  Před 28 dny +1

      @@arnaudkaho7137 for sure, learning c++ will improve understanding of what is ACTUALLY happening so much

  • @HiddenWorldsLLC
    @HiddenWorldsLLC Před 28 dny +1

    What you should be doing is watch videos from Unreal Engine, not random people on the internet.

    • @thegamedevcave
      @thegamedevcave  Před 28 dny

      i mean, yeah that's generally the most accurate info but unreal is pretty famous for having a real painful lack of learning materials.
      But for sure, it should be the first place you check stuff when you have questions in the off chance they give any useful info

  • @GiulianoVenturo
    @GiulianoVenturo Před 29 dny

    yup that's actually how I normally work with it. I use cast every time I can and also instead of functions I make custom events so then when I feel like I have everything I need I change to interfaces and it's pretty easy to replaces most stuff

  • @YoutubeAccountMan
    @YoutubeAccountMan Před 29 dny +1

    The biggest problem with casting is it loads a COPY of everything into reference, not a pointer. It's pretty easy to just use the memory tools to see that casting causes huge problems in games with any actual size. Indie games are small so it doesn't really matter, but in a AAA studio, you'll see it avoided like the plague for a reason.

    • @thegamedevcave
      @thegamedevcave  Před 29 dny +1

      i've heard things like this be said but I haven't found anything to support this. As far as I know using a cast or making a hard ref makes a #include on the c++ level.
      as far as I am aware, includes don't just dump the whole memory footprint of one class on top of another class. it will increase a bit, because definitions need to be stored of course but it doesn't copy the whole class over with it's entire memory footprint. Unless i am missing something. If you have some place for me to read more about this if I am missing something please do let me know and i'll try to make sure to include any updated info in the pinned comment :)

    • @ryanjdevlin87
      @ryanjdevlin87 Před 26 dny

      @@thegamedevcave yes IT DOES NOT copy the full memory allocation, the OP is incorrect. Thats why he works in AAA they know nothing but how to lie to make delays and push back deadlines, sry but we are not your project mananager you dont need to BS us... lmfao. Anyways after getting my distain for AAA out of the way there are plenty of ways you can test this in engine at any time. UE is smart enough to not just keep allocating memory to the same thing over and over. GG

  • @nichan008
    @nichan008 Před 28 dny

    Unfortunately, this is again propagating incomplete info.
    The reason why it's correct to tell people to avoid casting, is because the people that are the targets of that statement are the ones most likely to be harming themselves.
    Performance isn't the only factor to consider, it's just the one used to scare people away from casting the easiest.
    Avoiding casting is a principle of good software design and development. People that understand how to design software, understand when a piece of code is one off, unchanging, and will never ever need to be used or copied anywhere else are the ones that know when a hardcoded type reference is appropriate.
    And contrary to the message of this video: it's almost never appropriate.
    We don't teach people to write crap code, we teach them to protect themselves. And once they've learned what they've been protecting themselves from they take off the training wheels on their own.
    And you can say, 'I'm never going to need to write unit tests or share my code with other projects or people, I'm allowed to write crap code if I want to."
    And you'd be right. Everyone is allowed to write crap code. But why waste our time teaching them how to do it? Can you imagine how many people you're going to Dunning Kruger into thinking they know when hardcoded type references are OK? Including yourself.

    • @thegamedevcave
      @thegamedevcave  Před 28 dny

      people are scared into not using casts because yeah, if you use casts without understanding what they do your code will be pretty shit. but then they end up avoiding casting all together, still without an understanding of what it does and why they're avoiding it so they didn't really learn anything. "just avoid it" isn't a solution that anyone learns anything from.

    • @nichan008
      @nichan008 Před 27 dny

      @@thegamedevcave It's not a solution, its training wheels for the most basic of people. Telling them not to use the training wheels is the only thing those people will get out of this video.
      But my question to you is: regardless of performance, do you understand why you should still avoid casting?

    • @thegamedevcave
      @thegamedevcave  Před 27 dny

      @@nichan008 agree to disagree on how to give people information I suppose 🤷🏻‍♂️

    • @nichan008
      @nichan008 Před 27 dny

      @@thegamedevcave I'll take that as: you don't know why it's still a problem, but you choose to speak like an authority on it anyway.
      I don't have a problem with people expressing their opinions. But it's sad to see the less knowledgeable eat it up as fact, thinking they learned everything.
      If you really want to reduce misinformation and tell people the full truth I have respect for that. I'm letting you know: this video completely fails at that. Read up on good software practices and have another go. Or don't and make your money anyway, we both know which one is easier.

    • @thegamedevcave
      @thegamedevcave  Před 27 dny

      @@nichan008 no i'm just not wasting my time arguing with you because we clearly are coming at this from 2 different directions. I can respect your dedication to making sure no misinformation is spread. This video is aimed specifically at people who avoid casting because theyve been told "casting bad" without any nuance or more importantly, reasoning as to why.
      If someone takes this video as the other extreme and goes "oh so i can just be wasteful and cast all over the place" that' not really my fault at that point.
      There's always going to be people who try to simplify information and with that misinterpreted it. All i'm doing here is shining the slightest bit of nuance on a topic that many beginners take way too literally.
      and with that, unless you have anything more of value to add, i think this discussion is pretty much over now.