Casting Explained | Unreal Engine 5 Tutorial

Поділитися
Вставка
  • Опубліковано 26 лис 2024
  • *Notice Description Contains Affiliate Link
    Casting in Unreal Engine is often misunderstood. In this video, I do my best to explain and demystify everything regarding casting. We talk about why the object input is needed, what exactly it is, and why casting is needed in general. I also go over some best practices, and mistakes to watch out for when you encounter casting. This is the first in a series of Unreal Engine 5 fundemental concepts. If you find this video useful, please consider slapping a like on it, and thank you for watching!
    Thanks so much for watching! If you enjoyed this video please consider giving it a thumbs up, and if you want to be notified of more content from me, consider subscribing! Wish you all the best of luck with your projects!
    Want to learn more about Blueprint Communication? Check out these videos:
    Blueprint Interface Tutorial - • Blueprint Interfaces |...
    Event Dispatcher Tutorial - • Event Dispatchers | Un...
    !!Afffiliate Link!!
    Want to level up your learning while also helping the channel? Sign up to skillshare with my affiliate link below, and use code ANNUAL30AFF to get 30% off an annual membership!!
    Link: skillshare.eqc...

КОМЕНТАРІ • 91

  • @nikoheino3927
    @nikoheino3927 6 місяців тому +14

    finally an actual explanation, thank you. my blueprint is still broken, but atleast now its actually reading the values from the casting, progress.

  • @babyitsnatural
    @babyitsnatural 11 місяців тому +18

    Too bad there are so many other people on youtube teaching this subject badly. I think your channel has been hidden amongst the weeds of channels that either don't know how to teach or don't really care about teaching... but instead they just want to look smart so they talk really fast and give esoteric and superficial explanations unlike yours which are grounded in concrete examples that are relateable and thorough.. Seriously man, this is the single best explanation about blueprints I've ever gotten. Keep it up or maybe try to make a Udemy course on this. I would SO buy that SO hard.

  • @hypersapien
    @hypersapien Рік тому +5

    Thank you so much for going into so much detail about this, in laymen's terms. Casting has perplexed me for years, as an artist that doesn't use blueprints regularly.

  • @MilesKilometer
    @MilesKilometer 9 місяців тому +1

    Dude I was so confused about casting before I saw this video. Adding to this a few minutes of research about UE5 Class hierarchy and it all started to click for me, at least I hope it's clicking lol. I've been learning game dev since the start of the year mostly using c++ with some supplemental blueprint and I just wanted to say that your explanation helps me understand the code too! You've earned a subscriber.

  • @johnterpack3940
    @johnterpack3940 4 місяці тому

    I just installed UE 5 today. Getting ready to follow a tutorial that seemed really clear, but kind of glossed over casting. I'm familiar with programming, so you explaining it as inheritance really clarified things.

  • @lockekosta9014
    @lockekosta9014 Рік тому +8

    What's funny is this video helped me finally understanding casting from a C++ standpoint. Coming from Unity and C#, it was just irritating me how little sense it made and I like to understand things more than just memorize them. Kept getting, "Idk, it's just how you do it." Thank you.

    • @troyna77
      @troyna77 Рік тому

      Me too. I had to stop midway into a udemy unreal tutorial and watch this video to understand the prior tutorial. This YTber helped me understand.

    • @MilesKilometer
      @MilesKilometer 9 місяців тому

      @@troyna77 Is it the one where you're making the crypt explorer game by chance?

    • @_azterisk
      @_azterisk 8 місяців тому

      Same

    • @schmoborama
      @schmoborama Місяць тому

      " I like to understand things more than just memorize them. Kept getting, "Idk, it's just how you do it.""
      THIS
      THIS
      THIIIIIIISSSSSSSS

  • @KernalGohd
    @KernalGohd 11 місяців тому

    I've recently taken up Unreal, and found most tutorials lacking explanations of stuff like this. I ended up just reading the documentation instead. So many tutorials will tell you how to do something but not how it does something.
    With casting in particular I've justified it mentally as the blueprint picks up the casted object and looks at it, it is now able to interact with it and know about it.
    With a video like this I could have saved several hours on the weekend.

    • @samuelmertens4116
      @samuelmertens4116 10 місяців тому

      Can you help me out real quick? I watched it but still couldn't know what to put in the "object" pin in my project...
      I have my player, a character that chase me, and a safezone that despawns the character. I need in the safezone's BP a cast to the character BP, but everything i plug in the object pin gives an error/doesn't work

    • @KernalGohd
      @KernalGohd 10 місяців тому

      @@samuelmertens4116 Sorry for replying so late. If youre having a cast go back and forth between 2 objects, it can cause problems and not work, for something like that you may want to use a blueprint interface, which Tyler has another really good video on. If that isnt the case, then I think youd need to show pictures to get a better idea of what could be causing issues.

  • @Piotr-n8s
    @Piotr-n8s 23 дні тому

    Men, why you are not posting any more? You have such a gift for teaching.

  • @woetrei
    @woetrei Місяць тому +1

    The first 10 seconds hit right on the head!

  • @anthonysimmonsacousticmusi1098
    @anthonysimmonsacousticmusi1098 11 місяців тому +2

    Dude that was the best video I've ever seen of explaining what these things are and how they're used it's hard when you have no background in coding to try to understand the basics of what these things are why they're used and how they're used with examples so thank you you got my sub man

  • @CyborgNation
    @CyborgNation 7 місяців тому +1

    Thank you thank you, Everywhere i go people gloss over blueprints, your videos have helped me immensely

  • @Molls.Snowdon
    @Molls.Snowdon Місяць тому

    the first 10 seconds gave me a good laugh! Exactly why i wanted this video xD

  • @Mistform3D
    @Mistform3D 7 місяців тому

    Randomly got suggested this when looking up an issue… and was like “wait I worked on “Road Mode” with him lol. Nice video my dude. 👍

  • @autumnnotes7
    @autumnnotes7 8 місяців тому

    Thank you so much for this. You've got better, more concise explanations than everyone else on here. I hope you explore some of the more esoteric nodes. I want to feel smarter when I watch some dude speedrun an IK tutorial

  • @cosmotect
    @cosmotect 9 місяців тому +1

    Thanks!
    Since you have covered BP communication, perhaps next you could cover data types, data tables, data assets, structs, and everything related to storing game information and when is best to use each of them?

    • @TylerSerino
      @TylerSerino  9 місяців тому +1

      Actually working on those topics currently!

    • @cosmotect
      @cosmotect 9 місяців тому

      @@TylerSerino Hell yeah! Subbed, and looking forward!

  • @jamerthegamer13
    @jamerthegamer13 Рік тому +2

    Dude this video was perfect, I am attempting to create a game with several interactions and was getting frustrated with nesting casts, I got so called out at the end lmfao, looking to learn about blueprint interfaces!

  • @MarionPoittevin
    @MarionPoittevin 6 місяців тому

    Awesome, thorough, helpful tutorial. Thanks a bunch for this !

  • @MichaelBullo
    @MichaelBullo Місяць тому

    This is fantastic. Thank you.

  • @alexrybin3798
    @alexrybin3798 7 місяців тому

    Brilliant tutorial thanks a lot man!!!
    Honestly, I think cast is not the best name for what It does , this was number one for me why it was so confusing…

  • @DanVasc
    @DanVasc 5 місяців тому

    Thank you

  • @pixelsgraphicdesign
    @pixelsgraphicdesign Рік тому

    This really helped me! Thanks! I thought Cast To meant Sending data. I see now it means it's a throughput. And your details about object helped too, great examples!

  • @AlexVladimir-Harmanem
    @AlexVladimir-Harmanem 2 місяці тому

    6:46 "i´m gonna confuse you a little bit"
    *me already confused and overwhelmed

  • @arkemal
    @arkemal 9 місяців тому

    Excellent, thank you! You're a great teacher!

  • @sarahlynn7807
    @sarahlynn7807 11 місяців тому

    I would love a video on soft references. I am still scratching my head over them and most videos are very confusing about the use cases.

  • @ttguitarnoob
    @ttguitarnoob 10 місяців тому +1

    How did you know what my exact problem was

  • @franco-russo
    @franco-russo 2 місяці тому +1

    This didn't solve my problem. I just am more confused than when I started...What do I put in object?

    • @TylerSerino
      @TylerSerino  2 місяці тому

      What are you trying to cast to and from where are you trying to cast

    • @franco-russo
      @franco-russo 2 місяці тому

      @@TylerSerino Thank you for your response, but I have figured it out! Note to self, don't try to develop a game on hardly any sleep. Haha

  • @Builtit1
    @Builtit1 3 місяці тому

    IVE WATCHED THIS 3 TIMES 😭😭😭

  • @StarWyse
    @StarWyse 6 місяців тому

    oh my god, this just helped me out so much!! thank you so so so much!!!!!

  • @jiwik731
    @jiwik731 Рік тому

    I always find out what wildcard to use if it does not say any error or note. :D But i began to reroute casting with interface wherever i can or know how. But this video helps. Thanks.

  • @MarvenYassen
    @MarvenYassen Рік тому

    Thank you for the simple and thorough explaining

  • @Cjoudan
    @Cjoudan 2 місяці тому

    still clear as mud for my situation.

    • @TylerSerino
      @TylerSerino  2 місяці тому

      What are you trying to cast to and from where?

  • @joeypouladi
    @joeypouladi 4 місяці тому

    Clearly explained. 👍

  • @airplaneB3N
    @airplaneB3N 19 днів тому

    Seems like every tutorial I find uses the same textbook example using overlap events and the 'other actor' pin. Would have been nice to see a different example. I'm still totally stuck on this.

  • @knampf9779
    @knampf9779 7 місяців тому

    Very well explained

  • @DaveDavies-mq2fj
    @DaveDavies-mq2fj 10 місяців тому

    Many thanks , very helpful !

  • @schmoborama
    @schmoborama 17 днів тому

    So when you use 'Begin Overlap' it can use "Other Actor" to plug into the Cast ; do all other forms of interaction have that output?

  • @ivomollov3073
    @ivomollov3073 8 місяців тому

    If you were to make an interaction system as the one you described in the video, how would you do it without collision detection?

  • @py8115
    @py8115 9 місяців тому

    Thank you, it helped a lot!

  • @Hemrahban
    @Hemrahban 11 місяців тому

    thanks, that was a great explaination

  • @rynabuns
    @rynabuns 5 місяців тому

    I love Cube Guy 😭

  • @corey13
    @corey13 10 місяців тому

    Great video, thank you

  • @erdemgungor8674
    @erdemgungor8674 Рік тому

    this video helped a lot thanks man

  • @marcsimonsen
    @marcsimonsen 11 місяців тому

    This helped a lot =)

  • @maabul01
    @maabul01 Рік тому

    Thank you soo much. Perfect video.

  • @DesiHorrorShow
    @DesiHorrorShow Рік тому

    Great explanation.

  • @KDmadness18
    @KDmadness18 3 місяці тому +1

    Help!!! At 8:46 - the ONLY reason this all works is because you're able to click on your third person character, and set the cube_guy reference. This doesn't work for me because I'm doing the casting from my gamemode. So how am I supposed to click on 'gamemode' and set my cast references???

    • @TylerSerino
      @TylerSerino  3 місяці тому

      What are you trying to cast to from your game mode? Like I said, how you get an object reference is all going to depend on what you're doing. You have to ask if casting from your game mode to the object your trying to communicate with is the best method, or if it should be the other way. A lot of the time, I cast to my game mode from anything else, because you can simply call the "Get Game Mode" node and use that as an object reference

    • @KDmadness18
      @KDmadness18 3 місяці тому

      @@TylerSerino hmm perhaps I should flip it then? In my game mode I spawn different actors, and I was trying to cast to the actor in order to utilize a bool var that was in the actor. This is where I’m stuck because I’m not sure if while in my gamemode_BP, if casting to other objects is even possible.

    • @TylerSerino
      @TylerSerino  3 місяці тому

      @@KDmadness18 If you're spawning the actors in from the game mode, you shouldn't even need to cast, the blue pin coming out of the "spawn actor from class node" should give you a direct reference to the item you're spawning

  • @SplarcieRS
    @SplarcieRS Рік тому

    Nice video, me and a friend are new to UE5 and we can't seem to figure out the cast to class and to have that class go into multiple different object. How would that work? One class for multiple objects, like basically a cubeguy and coneguy, but it just is looking to see if its a shapeguy (any interactable object you'd want). That way you could pick up or see name of either shape/object. There's definitely a way I don't know that doesn't involve duplicating the same code over and over for each new object 😂Help would be greatly appreciated

    • @TylerSerino
      @TylerSerino  Рік тому +1

      You’d use inheritance, and cast to the parent class. So you’d have a shape guy that your cube and cone guy inherit from. Anything they have in common will go in the parent

    • @SplarcieRS
      @SplarcieRS Рік тому +1

      @@TylerSerino Solid, will check out your inheritance video to try and get a better understanding

    • @TylerSerino
      @TylerSerino  Рік тому

      @@SplarcieRS Youll also want to check out interfaces. Doesn't have to be my video, but interfaces are potentially another way to achieve this, however, if it's just something like a cube guy and a cone guy, i'd use inheritance. If it were, say, a cube guy, a cone guy, and a door (door is completely different), then you'd want to use a combination of the two. Either way, both super useful/important concepts to understand. Best of luck!

  • @artdrawing6682
    @artdrawing6682 Рік тому

    this explain new somthing abaut casting thanx but if ihave 3 diffrent class exmp bp 1 bo 2 and bp3 and haw to cast 3 actore in same cod letme explain more
    i have actor name AI from event tick i need to cast this 3 actor in the same time

  • @onlyasecond
    @onlyasecond 11 місяців тому

    thanks man

  • @UnrealEngine-y7t
    @UnrealEngine-y7t 9 місяців тому

    ty

  • @aakburns
    @aakburns 9 місяців тому

    Use the sparingly.

  • @lukaspellant5862
    @lukaspellant5862 8 місяців тому

    *My thought - What the heck is this object pin for.
    *Video starts - "if you clicked on this video you are probably trying to find out what this object pin is for".

  • @Ahmadnaweed786
    @Ahmadnaweed786 Рік тому

    Nice tutorial. I have watced your other videos about blueprint interfaces and event dispatchers and I like them, very helpful. But I have a problem which I am still unable to solve. I hope I can explain it in a few lines of comment. Simply put, I want to send data in other words cast to character blueprint from a game mode blueprint. I have tried CAST TO and INTERFACES and EVENT DISPATCHERS but none of them worked. All three of these have the same input pin, OBJECT or TARGET which I don't know what to plug-in in the game mode blueprint. Here is the setup: The game mode blueprint randomly spawns NPCs (enemeys) in waves in the level which the player has to fight and kill. Now what I want is that the dead bodies of the NPCs stay on the floor until the wave is finished and then get rid of the bodies cleaning the floor for the next wave. There is a node in the game mode blueprint that is called whenever a wave is finished and initiates the next wave, at this moment I want this node to send a message to the enemey character blueprint to remove the bodies from the level. If this doesn't clearly explain the problem I would gladly record a videos of it and let you watch it. Thanks

    • @TylerSerino
      @TylerSerino  Рік тому

      Off the top of my head, what I would do is create an event dispatcher in the game mode that gets called when the wave is finished, in your enemy bp, you can use the “get game mode” node and bind to that event dispatcher to destroy them
      Edit: you can use get game mode, and use that to cast to your specific game mode, then you bind

    • @Ahmadnaweed786
      @Ahmadnaweed786 Рік тому

      I have tried that already. In the enemy bp, the "get game mode" output pin doesn't connect to the input pin of the event dispatcher. Here is what it says: game mode base object reference is not compatible with bp game mode object reference.

    • @TylerSerino
      @TylerSerino  Рік тому +1

      @@Ahmadnaweed786You cant connect directly from the "get game mode" node, you have to cast to the game mode your using, which is going to be a child of the game mode returned by the "get game mode" node. So GetGameMode->CastToYourGameMode->bindtoeventdispatcher. If you need more help you can message me on discord tyler8106

    • @Ahmadnaweed786
      @Ahmadnaweed786 Рік тому

      @@TylerSerino ok thanks. I will do this and let you know the results.

    • @Ahmadnaweed786
      @Ahmadnaweed786 Рік тому

      ​@@TylerSerino it worked! thanks. And I have also sent you a friend request on Discord.

  • @venomtang
    @venomtang 9 місяців тому +1

    have a like.

  • @MikaeloSanJose-gk8pl
    @MikaeloSanJose-gk8pl Рік тому

    Hi Tyler. I am trying to make two BPs use each other's variable.
    I have a player character BP and an actor BP as an ability projectile.
    I would like to have multiple different ability actor BP.
    I am trying to increase the ability's damage increase by the players bonus damage.
    I have tired the method at 6:50 of the video as well as getting all actors of the class and then connecting it to the cast to node.
    I am not sure what I am doing wrong:(
    I do have an imgur link that i could send to you
    Any help would be greatly appreciated
    Thank you in advance!:)

    • @TylerSerino
      @TylerSerino  Рік тому +1

      Since it’s a projectile I’m assuming your spawning them in during game? If so each time you spawn one in, that’s a new object and when you destroy them the object reference will no longer be valid. If I’m correct and you’re spawning them in during runtime, what you could do is set the variable for bonus damage on the projectile as “expose on spawn”. Click the variable in the blueprint and look on the right hand side in the details panel. Now, when you use the node “spawn actor from class” that bonus damage will be an input. If I’m wrong and your not spawning it in, or if you’re still having trouble, send me the imgr link and I’ll try to help

    • @MikaeloSanJose-gk8pl
      @MikaeloSanJose-gk8pl Рік тому +1

      @@TylerSerino Yes thank you so much!!!!! This is exactly what I needed I can't thank you enough:) I really appreciate your videos!

  • @alexgomez-bi2bk
    @alexgomez-bi2bk Рік тому

    A blueprint is a class that can be an object instance. An actor is considered its parent class, BUT the child class is also called actor. So when the "other actor" pin gets connected to the object pin the logic flow is Get Owner: target is actor component is essentially finding the child class of the parent class actor and outputting to Object pin which represents the instance of it. Then cast to references the blueprint to access which in turn "gets" target first name. Now for other actor to Object pin overlap executes on any actor and Cast to operates within the parameters of itself because the "Object" is the instance of the cast to blueprint class. I'm not too sure about overlap being executed but not going through or just simply not executing at all. The reason why I am not sure is because the Object pin is an input I THINK, not an output. I just started unreal like a month ago don't really grasp the concept that well

  • @andristefanus
    @andristefanus Рік тому

    mystery solved

  • @justinhowlett5316
    @justinhowlett5316 3 місяці тому +1

    i hate unreals cast to. way too fucking complicated to figure out. what a mess

  • @Si-Toecutter
    @Si-Toecutter 13 днів тому

    waste of time unless your doing begin overlap

  • @schmoborama
    @schmoborama Місяць тому

    Thanks but you actually skipped over what to connect to the Object pin when casting to an Actor 🤦‍♂ Just creating an Actor variable doesn't work

    • @TylerSerino
      @TylerSerino  Місяць тому

      Are you casting to the base actor class or a class you created that inherits from actor? You can’t just plug an empty actor variable in, you need a variable that stores a reference to whatever class you’re trying to cast to

    • @schmoborama
      @schmoborama Місяць тому

      ​@@TylerSerino Hey thanks for responding!
      When you do that, it warns you that you don't need to cast anymore, since you already have a reference to that actor class... ?

    • @schmoborama
      @schmoborama Місяць тому

      Ok I watched again and see you covered the warning "You don't need to cast to that actor".
      So if I'm not using Overlap, do I just make a box to reference to in an actor reference variable? Or a BP_box? I think I tried that and it didn't work - ? If it 'should' work, I'll keep trying it, I must have missed something. But it would be great if you could do some other examples aside from Overlap!

    • @TylerSerino
      @TylerSerino  Місяць тому

      @@schmoborama It ultimately depends on what you're trying to do. You can use overlaps, line traces, you can create variables that you set as instance editable and set them in the details pannel in the editor if they aren't going to change. If you were trying to talk to your game mode, you'd use the "get game mode" node and cast using that. Ultimately what it comes down to is obtaining a reference to the object you're trying to talk to, and if its not a direct reference, cast. But how you do that depends on what you're doing

    • @schmoborama
      @schmoborama 17 днів тому

      ​@@TylerSerino
      Yea that's the problem - how you should do it depends completely on what you're trying to do, it's different for everything, and it's different enough that you have to be shown how for each one - and no one is showing how for each one,, only a couple. which leaves everyone else with their hands in the air 🤷‍♂
      "what it comes down to is obtaining a reference - if its not a direct reference, cast"
      But casting is what I need the reference for in the first place - ??
      Sorry to keep bugging you and I hope I'm not just being stupid - but I have to keep at it until it clicks