Unreal Engine - Is "Casting" Bad?

Поделиться
HTML-код
  • Опубликовано: 13 фев 2022
  • How Bad Is Using the "Cast To" Node! Information for both Unreal Engine 4 and Unreal Engine 5. (ue4, ue5)
    🕺 Come join the Team Beard Discord​​ 🕺
    If you're a game developer and looking to join a friendly game dev community which ranges from expert to professional, be sure to hop into the discord! We're always looking for more awesome people to join!
    / discord
    ⚜️Check out my Marketplace Asset ⚜️
    🗡️ Mele 🗡️ www.unrealengine.com/marketpl...
    🏹 Ranged - www.unrealengine.com/marketpl...
    ✨ Magic - www.unrealengine.com/marketpl...
    ⚔️ Package ⚔️ - www.unrealengine.com/marketpl...
    🔪 Basic - www.unrealengine.com/marketpl...
    Useful Article: raharuu.github.io/unreal/hard...
    🤝 Ways to Support The Channel 🤝
    Patreon: www.patreon.com/JonBeardsell?...
    Buy Me A Coffee: www.buymeacoffee.com/JonBeard...
    All support will go towards helping me produce RUclips content and tutorials full time.

Комментарии • 43

  • @earthbornjim9975
    @earthbornjim9975 2 года назад +2

    Thanks heaps for this and the Interface video you made. I didn't realize just how wrong I was doing things by setting references here and there and using casting when I really just needed to use Interfaces. I guess I never really understood hard references and their impact as everything was working and seemed easy enough. I've now gone through my project and modified everything I could to interfaces and when looking at the reference viewer it's been cut down dramatically for most things. Its also made things so much easier to manage as I don't need to remember all the different references i've set and if they're going to cause trouble down the line. Thanks heaps!

    • @Beardgames
      @Beardgames  2 года назад

      Hey it's a slow process improving efficiency, looks like you're well on your way now good job 😎 Anytime brother thanks for watching and supporting the content!!

  • @syrus2128
    @syrus2128 2 года назад +7

    Very interesting! I never knew cast nodes could be such a pain when working on big releases. I used to never use them and instead use "get all actors of class". This was all fun and games until I stumbled upon overlap events lol. Anyways, nice video and very instructive!

    • @Beardgames
      @Beardgames  2 года назад

      Thanks Syrus hope it helped 🙂

    • @pawprinting
      @pawprinting Год назад

      @@Beardgames What about the performance cost of casting directly to a C++ gameinstance? I mean this is something that is essential to programming. In most cases those things have to be used along with onTick as well to constantly update the code.

  • @fracturedfantasy
    @fracturedfantasy 2 года назад +1

    I like the point you make about the hard references that are already there. A good thing to do would be to check the reference first, and then make your decision. As always thanks my friend. 💪

    • @Beardgames
      @Beardgames  2 года назад +1

      Anytime brother thanks for the kind and intelligent comments as always🙏👊🏻

  • @ZzZz-dr7uq
    @ZzZz-dr7uq 2 года назад

    great video short and precise

  • @crown9413
    @crown9413 2 года назад +11

    I would also add, take advantage of the blueprint hierarchy its better to cast to a base level class like Actor or Pawn. For example say you have ten different types of unit in rts game casting to each one will force the game to load in all the assets related to those units which will hold up a ton of memory, you could instead cast to a parent of those classes in which you have the minimal functions you need for them.

    • @Beardgames
      @Beardgames  2 года назад

      Well said good sir

    • @shannenmr
      @shannenmr 2 года назад +3

      Some potential alternatives / optimisations:
      * Have Base C++ classes as Casting to those doesn't create a hard reference
      * Use a Interface to communicate between Classes that doesnt create a hard reference
      * Create a Base BP class that contains just the logic and code and then child class with just the Object References which take up memory like Meshes and Sounds etc ... this way you only creating a hard reference to a code only BP
      * Use Soft Object References in your BP's to then later in your code ASync load items that take up large amounts of memory as its needed, similar outcome to Base class BP's as Casting should only hard reference the code portion of your BP or anything you didn't Soft Reference in the BP

    • @dadlord689
      @dadlord689 Год назад

      You don't need to cast when you accessing inherited functionality. When you passing an object as it's ancestor - there is no casting goin on. And downcasting is just a flaw in architecture design. But that's why you have interfaces and they are allowing multiple inheritance (you can have as many as you want). But yet it is better to use composition over inheritance (components pattern).

  • @samiam.402
    @samiam.402 2 года назад

    So when I have an actor reference as a character within another actor blueprint, is this also considered a "hard reference"? So when I do that and edit it on instance within my level, is it as harsh on memory as casting is or is the easier?
    Also, how would you measure how harsh these references are on performance?

  • @StarvingWolff
    @StarvingWolff 2 года назад

    Hey man i have an issue with your tutorial for inventory system. See when we press the same item slot it hides the Use/Drop button just fine but not when pressing a different item slot, so both show and it looks super bad. how can we make it so it hides it regardless of which item slot we press? a tutorial for that would be amazing!

  • @sdrawkcab_emanresu
    @sdrawkcab_emanresu 2 года назад +3

    Can you make a tutorial on the best ways to avoid cast nodes? I know you already made one about interfaces, but there are other situations, where that doesn't work, and an overview would be great

    • @Beardgames
      @Beardgames  2 года назад

      Have a read of the article in the description it goes over some other methods to use to avoid them but primarily it's blueprint interfaces my friend 🙂

    • @tuatec
      @tuatec 2 года назад

      I use interfaces a lot. This does not introduce a hard reference. 😉

  • @BlueprintBro
    @BlueprintBro Год назад

    Thank you for this

  • @geeksinsuits
    @geeksinsuits 2 года назад

    As new to UE5 BP i just learned how to use Cast node to communicate and i was happy about it lol !

    • @Beardgames
      @Beardgames  2 года назад +1

      Don't change my good friend, learning passing references is a long process of learning which you build gradually! Stick with the cast know but know that there are more efficient methods which you can adopt over time 🙂

  • @DoctorMGL
    @DoctorMGL Год назад +1

    in my experience the only blueprint that cause a lot of performance drop when casting it is "Character Blueprint"
    it has a heaviest connection compare to the rest of blueprints in your game
    because it have to read trough all the < key binding /animations/ tweaking/ animMontages / physics / vfx /sfx / ik /bones .. ta ta ta ... etc >
    all in one file
    so i'd cast other blueprints but avoid as much as you can casing characterBP itself
    in general Avoid casting heavy blueprints that has a larg heavy codes
    and use interface whatever you fall into such situation

  • @ashensamurai8072
    @ashensamurai8072 2 года назад

    where can i hire devs with your skills for a project?

  • @gamerdweebentertainment1616
    @gamerdweebentertainment1616 2 года назад +1

    and have Tons of components on player character instead :)
    For me coding gets a bit complicated, for my sanity sake I started to name functions, dispatcher etc by adding a refrence...
    Kind of jarring when you have multiple Interact functions and such or recently on clicked...
    On clicked, call on clicked, bind on clicked... etc

  • @ThatOpinionIsWrong
    @ThatOpinionIsWrong 2 года назад +1

    Wouldn't setting variables as references solve this problem? For example whenever you want to reach PlayerController inside your Character you would have to GetController > Cast to BP_PlayerController everytime, what if instead, on BeginPlay or some other event that you want to set up your character you would cast to PlayerController only ONCE and saved it as a variable inside the Character blueprint? That way everytime you wanted to call PlayerController you would simply use the already made variable?
    I know this doesn't apply to dynamically created references but it would save performance when dealing with things that are regularly called.

    • @Beardgames
      @Beardgames  2 года назад +1

      Unfortunately simply having the cast to node will create a hard reference. That being said it's still more efficient creating a reference to it then to keep using the cast to node 🙂

  • @tuatec
    @tuatec 2 года назад

    Why do casting nodes increase memory consumption if we use references to store them? I thought a reference is kind of a pointer in C++ and there we only need to store the address.

    • @God0fTime
      @God0fTime Год назад

      yea in c++ if you cast to a c++ class I heard that is exactly what happens, but when you cast to a BP_ then It loads the entire bp and its casts

  • @chaosordeal294
    @chaosordeal294 2 месяца назад

    If you're loading a character, you probably want the model, mats, functions, and animations, anyway. Better to load them up front than during play.

  • @kendarr
    @kendarr Год назад

    So, I have a character, and I often cast from my guns to the character, I'm just making a hard reference to my character right? Which for me is good since the character is my player, it will always be loaded. Or by casting to the character from all of my 5 guns, I'm loading all of these 5 guns in memory? EDIT: I'm casting to the character because my guns have all of their code to function in them, so all firing, ammo, everything is in the gun blueprint, the character only fires, reloads and holds the total ammo.

    • @kendarr
      @kendarr Год назад

      @@themeangene It's fairly small, something like 10v10 free for all or something like this, I wanted to get my hands dirty with game dev, and yes I'm aware I should not have choosen an online game at first lol

  • @KJ-rc3io
    @KJ-rc3io Год назад

    Is casting to player character bp bad? Isn't that blueprint always loaded into memory since it controls the player?

  • @trenerjakub2605
    @trenerjakub2605 2 года назад

    Hi, I have a question. what would be your advice for developers who want to make an fps game? where to start? or where do you start first? thank you for your answer have a nice day and much success.

    • @crown9413
      @crown9413 2 года назад +1

      Look at as many projects as you can there's a few on the learn tab of the launcher particularly the content examples, there's also a shooter game example there. Make minigames and game jams. Start small one feature at a time. I'm a tech artist that's how I got started.

    • @ThatOpinionIsWrong
      @ThatOpinionIsWrong 2 года назад +1

      Look for FPS tutorials on youtube. Look for channels "SargKyle", "Awesome Tuts", "vPoly", they made tutorials for UE4 but it's pretty much the same case on UE5.
      Start simple at first, for your first project I'd recommend making something like original DOOM from 90s. Focus on making the guns work, shooting, picking up health & ammo, enemies, opening doors, keycards, just the absolute basics. DOOM is a smple game and you will teach yourself the basics without worrying about milion trivial things of the modern shooters.
      Try to make a working game from start to finish, as in, make a functioning main menu, some levels, gameplay loop (going from the start to the end of the level, dying, killing, objecties etc.).
      Good luck.

    • @Beardgames
      @Beardgames  2 года назад +2

      Just keep learning my friend! Even if it's not FPS related just learn all the ins and outs about unreal as they all come together regardless of what game you're producing 🙂 good luck Trenor!

  • @nicholaspatton3797
    @nicholaspatton3797 2 года назад

    I have a question relating to game development. If someone wanted to create a game where players can tame monsters in order to either fight other monsters, solve puzzles, etc., how would someone set it up?

    • @PsyCoCinematics
      @PsyCoCinematics 2 года назад +1

      One step at a time. Break all the things you want down into bits, then cut those bits down even smaller if it helps. Like asking how to make a sandwich, you'll need bread, meat, cheese, mayo, etc. But you'll also need a plate to put it on, the bread and other ingredients were in their own containers, a knife to spread the mayo was made from some metal. The drawer the knife came from has different sections and is a shelf. The shelf can open because of wheels. Wheels work because of gravity. Gravity works because the Earth revolves around the Sun etc etc. Worrying about ALL of that at once doesn't help. But doing one tiny bit at a time lets you piece it all together, and fix parts that need touching up along the way ^_^

    • @nursultannazarov8379
      @nursultannazarov8379 2 года назад

      @@PsyCoCinematics pffft. Wrong

    • @PsyCoCinematics
      @PsyCoCinematics 2 года назад +1

      @@nursultannazarov8379 Haha, okay.

    • @samiam.402
      @samiam.402 2 года назад

      Just curious how much unreal experience you have? If it's not a lot, I would write down all those feature you want for your game, and practice by making even smaller projects that have just a single feature done, really well. Then as you are more comfortable with it, you can use all your knowledge to put it all together into one big project like you said.

  • @Will_278
    @Will_278 2 года назад

    Hello could you make a tutorial where a character automatically unequips a sword when not in combat please

  • @DuneGames
    @DuneGames Год назад

    I don't see how interfaces help with memory. You still have to call the interface function on that 'reference' when you use it. And the caller will reside in memory until the reference interfaced function is done processing. Interfaces help with communication by making it available on objects that typically don't have that 'interface'. If the object your calling has a 'AddDamage' function, you wouldn't add an interface to simply call 'AddDamage' on it. You'd call the intended AddDamage. Though if it was a wall, which typically don't take damage, but you wanted it too. Then an interface to handle 'AddDamage' would suit it just fine. And you'd cast the wall actor to the interface, and if it was valid, you'd call the interface > 'AddDamage' on it.