[UE4] How to CAST! (Casting to objects and classes)

Поділитися
Вставка
  • Опубліковано 19 чер 2024
  • Casting is a big part of learning Unreal Engine; I hope this video helps ease some of the pain!
    0:00 - Thesis
    0:36 - Video actually starts
    3:39 - Casting to classes
    Join the fun: / discord

КОМЕНТАРІ • 149

  • @HyperCazual
    @HyperCazual 3 роки тому +62

    I learned something new, but it did not solve my problem.

    • @skyblade7438
      @skyblade7438 Рік тому +3

      I have never seen such a perfect description of coding.

    • @Symphonio
      @Symphonio 8 місяців тому +1

      He went wayyy too fast, showing off way too much that he’s good at what he does but not really explaining

  • @bodacious705
    @bodacious705 2 роки тому +66

    good info, but for beginners I think it would help to go a bit slower and reiterate key points. I think the video was pretty good, but just as a tip for beginners like me, explaining the material in several relatable ways helps reinforce what the viewer is learning in their mind and store is there more effectively. Just my thoughts. keep up the good work!

    • @supjay3945
      @supjay3945 2 роки тому +8

      Lol yea he goes so fast it seems hes talking to himself.

    • @Zeriel00
      @Zeriel00 2 роки тому +4

      @@supjay3945 Yea this doesn't help me at all. I've used casting before but I don't know a lot about Widgets. So He's talking about a lot of different things at once when I just want to know what goes in the object pin.

    • @supjay3945
      @supjay3945 2 роки тому +1

      @@Zeriel00 try slowing video down, it helps but makes him sound drunk.

    • @supjay3945
      @supjay3945 2 роки тому +1

      I forgot I watched this video before and tried to follow the tutorial but he went too fast and flew by the simple steps (closing deleting stuff) that I got lost. Was gonna comment but saw my old comment. Lol

    • @unreasonablebastards753
      @unreasonablebastards753 2 роки тому +1

      Yeah this is a super confusing way to explain this concept. Weird approach to use widgets.

  • @Garycarlyle
    @Garycarlyle 3 роки тому +9

    Great video. I love how you are building repport with us by relating to the errors.

  • @WhiteTechWT
    @WhiteTechWT 3 роки тому +1

    OMG I love you. I have been struggling for 3 days trying to get this to work. You're awesome!

  • @jorgecastilleja5356
    @jorgecastilleja5356 2 роки тому +3

    Thank you, this is great, This is exactly what I was looking for!

  • @guritfakgill8173
    @guritfakgill8173 2 роки тому +3

    I've been trying to figure this out for the past 2 hours, then i saw this and you saved my life. Thanks man

  • @nathantew7638
    @nathantew7638 Рік тому +3

    This is the first video i've seen that actually explains casting in a understandable way. Great video

  • @evelynperez4521
    @evelynperez4521 3 роки тому

    Thank you for this great explanation!

  • @gibsonfx3819
    @gibsonfx3819 3 роки тому +1

    Thank you so much! This was very helpful.

  • @alexogar9300
    @alexogar9300 3 роки тому

    I just want to say thank you very much! You re awesome! Cant thank you enough

  • @lairdkim405
    @lairdkim405 3 роки тому +1

    Finally, I got the answer after weeks of searching... God Bless you man

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

    maaan, thank you A LOT!!!! this video is exactly what i was looking for, is a solution for my problem!

  • @leonidkhamadakov7778
    @leonidkhamadakov7778 3 роки тому

    Thank you so much! You fixed my problem. Its sad how you only have 66 subscribers. Here brother, have a sub

  • @musikalniyfanboichik
    @musikalniyfanboichik 3 роки тому

    damn, this video is a lifesaver. thanks!

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

    exelent !! 🙌🙌 I saw a lot of tutorials but this is the best, you won a like and suscriber sr

  • @stevenkent5351
    @stevenkent5351 3 роки тому +11

    Great video, i wish i had this back when i started 3 years ago, because casting was THE HARDEST thing to over come when learning how to use UE4. I might make a suggestion, tell people how expensive casting is and how to minimize the impact by creating references in begin player when heavy usage will be needed.

    • @dreadtrain2846
      @dreadtrain2846 2 роки тому +2

      Interfaces ...

    • @kenalpha3
      @kenalpha3 2 роки тому +1

      Where is a vid that explains the name of this alternative?

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

    JAJAJA Thank you so much ! This video makes me happy!

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

    I haven't tried it yet but it looks like its what I needed. will edit tomorrow but THANK YOU!!

  • @sh1nyplayer
    @sh1nyplayer 3 роки тому

    Thank You! I was your 160th Subscriber

  • @jessesolomonscott
    @jessesolomonscott 2 роки тому

    Well Explained thank you so much

  • @JessicaMarinaRushie
    @JessicaMarinaRushie 3 роки тому +5

    This is brilliant! This has fixed my problem, thank you!

    • @milan.980
      @milan.980 3 роки тому +1

      hi @Jessica Marina Rushie , I think this helped me also

  • @ishansawant7218
    @ishansawant7218 3 роки тому +1

    Perfect pace and clear explanation! Thank you. Subscribed!!

  • @jacobmmm8260
    @jacobmmm8260 3 роки тому

    Thank you. Your video will very helpful for me;)

  • @hosseinnafisinia9151
    @hosseinnafisinia9151 3 роки тому

    Easy, Fast & Pro. THX MAN

  • @cecill2520
    @cecill2520 3 роки тому

    thank you:)very helpful

  • @Xoremus72
    @Xoremus72 3 роки тому

    So I have an issue where I Want to Cast To BP_CurrentWeapon actor, and get the ammo decrement from a function within to read out on a Text on my UI Widget ? the gun in question spawns on the character when play is hit. Any help would be greatly appreciated.

  • @fouadelsadany4939
    @fouadelsadany4939 3 роки тому +1

    thanks a lot! , but how to bind events of a button in widget, inside an actor blueprint? like an actor to widget communication.

  • @clebo99
    @clebo99 2 роки тому

    Very nice!!!!!

  • @andreiandgames9581
    @andreiandgames9581 3 роки тому

    GRAN VIDEO, MUY BUENA FORMA DE EXPLICAR

  • @shaolung5342
    @shaolung5342 3 роки тому +1

    4:42 I have been looking for that answer for... ever... LOL Thanks

  • @serped
    @serped 2 роки тому

    Thanks for solving my problem

  • @tacca4720
    @tacca4720 3 роки тому

    Nice video, cheers. Interesting playing with bluerpints (determined not to bail back to C++). Still trying to create an array in one actor, and view array elements in another actor; think I've made it fair more complex than I need to, but hey, blueprints are fun..... right :)

  • @schrottiyhd6776
    @schrottiyhd6776 3 роки тому +9

    Best way for Refferences: Cats or A LOT OF CATS

  • @SkSafowan
    @SkSafowan 3 роки тому

    Man, you Deserve More Sub !!!

  • @360ambiencevideos
    @360ambiencevideos 2 роки тому

    How might I use a widget in the world in VR and use it to call functions inside my VR pawn?
    I want a 3d widget visible in front of me when my motion controllers overlap, and I want to use the widget to call functions of my Ai companion using my VR pawn.

  • @patrickmiller1723
    @patrickmiller1723 2 роки тому

    I'm making a game with a reloading blue print but I cant connect the ammo to the character the ammo connects to the gun just fine but I cant press the R input it doesnt work in the gun blue print

  • @QER4992
    @QER4992 3 роки тому +3

    unfortunately, this didnt work for me, Im trying to make it so when I have a suppressor equipped (on my gun) it changes the sound by a boolean whether suppresor is equipped or not and Im getting this from a cast to node but it doesn't work even when I tried to use the cast to class node but I would say this is a great video!

  • @Saas_1
    @Saas_1 3 роки тому

    Thank u a lot!

  • @3DWithLairdWT
    @3DWithLairdWT Рік тому

    This is good, but leaves out a really important point.
    "Casting" is literally just a way to compare two things --- when talking about Blueprints in Unreal.
    Is the *Object Reference* I pass in the same type as the *Cast To **_____*
    An *Object Reference* points to an address in memory
    A *Class* is a layout of data in memory
    So we take that layout, and then compare it to the actual data at the address our reference give us and see if they are the same.
    "The same" means::
    They are both the exact same type/class and therefore you can access data/functions etc from it because you now know how the data is laid out in memory
    OR
    the *Object Reference* inherits from (ex. is a Child Class) of the *Cast to **____* --- and therefore you know that the child has at least all of the parent data laid out in memory in the same way and you can safely access the contents.
    So in closing, it is important to keep in mind that Casting is in no way a form of communication between objects, it is a way of determining how you can interpret an Object Reference

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

    thank you!!

  • @ruslangolovchenko6797
    @ruslangolovchenko6797 3 роки тому

    Hey! Thanks a lot for the video! And if we work with an actor, where can we get a reference for an object?

  • @Amelia_PC
    @Amelia_PC 2 роки тому +1

    That was a great video!
    I still can't Cast to Chameleon (Post Processing BP from marketplace) class in my Player Blueprint because of that stupid Object reference. Man, how I hate casting...

  • @tacticalbacon8064
    @tacticalbacon8064 2 роки тому +1

    awesome but what if i have a Boolean in that class that i wish to change its value from a different BP what then?

  • @Alex_Panagiotidis7
    @Alex_Panagiotidis7 2 роки тому +1

    when i create widget and add parent it doesnt has a object(selection)

  • @sunnymon1436
    @sunnymon1436 2 роки тому

    How can an object reference in the construction script of a parent class exist in the world, if the object's creation code (in this case "create widget" is run at "BeginPlay" - surely the parent's construction script is run first, and wouldn't find the object reference because the parent's construction script MUST run before the child's BeginPlay (not finding the object) before the object's code (which runs at begin).?

  • @YamamotoGenryusaiShigekuni
    @YamamotoGenryusaiShigekuni 3 роки тому +1

    You see the actual confusing question is "Is the 'Parent' widget created after 'cast to me' or vice versa? That part is confusing. The problem is always that inheritance bs. So which one is which? As far as I've understood, you created a subclass and named it "Parent" for some reason and then used cast to me get password stuff from a parent-like (at least I felt that way) widget named "cast to me". So which one is it? I need a plane, simple answer please.

  • @Legend64Project
    @Legend64Project 2 роки тому

    Okay why is this so difficult? I can't just make a simple reference to another BP that I want to cast to and hook that into the object reference pin? I can't get the cast to node to work at all.

    • @Legend64Project
      @Legend64Project 2 роки тому

      For those who are also stuck, you can use a "get all actors of class" node and hook it into a "get" node and then connect that into your object reference and it actually works.

  • @mathiasmiranda6825
    @mathiasmiranda6825 3 роки тому +2

    I have a question, instead of getting the password how about if i want to change the value, like set a boolean variable to false or true. How can i do it with clases?
    Good video btw, thx mate.

    • @aaronhunt7204
      @aaronhunt7204  3 роки тому +2

      A successful cast will return the desired object reference, meaning you can set your boolean value using the "As (Your Class Name)" pin.

  • @adrianmiszczuk8061
    @adrianmiszczuk8061 3 роки тому

    So cast to is really useful when you want call this variable like password in string from other blueprint, in this case Widget and also with custom events

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

    this tutorial beats the whole purpose of casting in the first place!
    I only clicked on it cuz it sounded funny!
    question is not how to cast! question should be when to cast!
    obviously casts failing is not a bad thing! its not an error! its literally what casting is for!
    u cast to make sure certain logic only happens when a specific taken object is valid and of a certain type! and if its not u want to do something else instead ...
    you never cast just for the sake of casting!
    cuz that is just stupid to do so! if you know the object will always be of a certain type u can just store it in the certain type container and get rid of the need to cast!
    or if u need to access certain events , functions or variables inside your object , its cheaper and in long run much safer to use interfaces instead of casting!

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

    I understand your explanation but I think it's solving a different issue than in the title possibly. Suggestion to help beginners: define Instance and Reference for people that don't know WTF that even is. I've got a situation where Set Object Class isn't recognized in the same scope yet. Wondering if I just need to find another function instead of SetChildActorClass. Like a Create function that I haven't been able to get to work in my case. Cool. Thanks for the info.

  • @elfincredible9002
    @elfincredible9002 3 роки тому

    I'm trying to cast a blueprint with mesh to a widget. or the versa....and I'm lost somewhere.

  • @markojotovic8991
    @markojotovic8991 2 роки тому

    working without error but for example it doesnt work with integer.. the default integer value doesnt not make changes

  • @CortVermin
    @CortVermin 3 роки тому

    so... why would i use cast instead of get all actors of class and get any of these? or "get actor of class" if i need that reference thou

  • @zinze00
    @zinze00 2 роки тому

    So.. How do you cast from an actor, to your character and then send the infomation to a third actor? Cus thats why im here, not for widgets..

  • @hottestmanevar
    @hottestmanevar 3 роки тому

    You're the best

  • @MagiCityProductions
    @MagiCityProductions 3 роки тому

    This is a very good video, but I will have to watch it several times because it was so fast, but it is exactly what I needed. Thank you.

  • @I-Maser
    @I-Maser 3 роки тому +7

    1:34 Your goddamm right

  • @clebo99
    @clebo99 2 роки тому

    Can you do one where I’m casting to an NPC to either follow or not follow me?

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

    I've tried every tutorial on the internet including this one and none of them have worked for me, I just wanted to display the health of each AI in my level, but it would either fail or only show the health of one AI or all of them as a class but wouldn't update for each AI, what ended up working was casting to the widget from each AI on event tick, no idea if this is the correct way of doing it but it's literally the only thing that has worked. For some reason every tutorial has the widget casting to the actor to get an update of its health, no idea why.

  • @superfluousvii9686
    @superfluousvii9686 3 роки тому

    how do you cast to landscape?

  • @NoahThomas29
    @NoahThomas29 2 роки тому

    Wow do i find it soo funny that you made the password turtle 😂😂😂

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

    thanks

  • @ChaseTheVase
    @ChaseTheVase 3 роки тому

    Dumb beginner question but what if I'm not using widgets? I have a Boolean in one Blueprint that I need to get to another

    • @kolza4067
      @kolza4067 3 роки тому +1

      I have the same problem so if u found the solution i would appreciate an explanation

    • @ChaseTheVase
      @ChaseTheVase 3 роки тому +1

      @@kolza4067 I found something that works for me. Say you’re in a blueprint named “yellow” and you need to reference a blueprint named “green”. In yellow, make a variable. The variable type (where you would pick Boolean, integer, float, string, etc) literally type in the name of the blueprint you’re referencing. So in my example I would type “green”. Make sure that you check “Instance Editable” in the top right for the new variable. Then I would drag my “yellow” blueprint into my scene. In the details panel of “yellow” I can now drag in my “green” blueprint and then reference anything in “green” from “yellow”. Hope this helps!! If you have a question I’ll do my best to answer.

    • @kolza4067
      @kolza4067 3 роки тому +1

      @@ChaseTheVase thanks so much It worked!

  • @SenEmChannel
    @SenEmChannel 2 роки тому

    I will try this tomorrow. Bjt tutorial kind a fast to me.

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

    How to cast to "Get Class Display Name" ?

  • @IrocZIV
    @IrocZIV 2 роки тому

    Had to watch at .25x speed a few times, but good info

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

    It helped but is that really the only way to get object i feel not!.

  • @benjaminhawklyn8490
    @benjaminhawklyn8490 3 роки тому

    2:32
    I was having trouble getting object reference in the widget until I looked it over again and this part i

  • @Othman1992on
    @Othman1992on 3 роки тому

    Thank god for youtube's slowdown function

  • @nicolascasanova4853
    @nicolascasanova4853 2 роки тому

    i love you

  • @OwenPrescott
    @OwenPrescott 3 роки тому +1

    I would have avoided so many stressful moments if I knew you could do that 2:50

  • @PsyCoCinematics
    @PsyCoCinematics 3 роки тому

    I can follow along with widgets, but I think I'm missing a step when it comes to how this applies to actors. For example, here ya get around the missing reference with Create Widget in the level BP. There's no Create Actor. So... ah?

    • @aaronhunt7204
      @aaronhunt7204  3 роки тому

      Well, you can always spawn the actor. If the actor is already spawned, you can create a variable inside the parent and set it manually as an instance editable actor reference. 😄

    • @PsyCoCinematics
      @PsyCoCinematics 3 роки тому

      @@aaronhunt7204 I did that but I cannot cast to the actor bp without the error you showed/no error and cast failed, basically 2:26 in your video. Does this method only work on level BP?

    • @aaronhunt7204
      @aaronhunt7204  3 роки тому

      @@PsyCoCinematics Casting is the same everywhere. What is in your object pin?

    • @PsyCoCinematics
      @PsyCoCinematics 3 роки тому

      ​@@aaronhunt7204 I plugged the object reference variable which is exposed and editable. Accidentally made one an Actor but changed it to the proper one but still no-go. I *did* manage to get communication in a separate bp, but it isn't ideal. I have a health variable on the 'password' bp to try and edit the health from another bp and make sure I 'got it'.
      On the Thirdperson BP I setup
      F key>Cast to ActorWithPassword (with plugged in Object Ref)>Printstring with Password plugged in. Fails.
      On the Level BP I setup
      G key>Spawn ActorWithPassword (plugged in player location)>Promote Return Value to Variable>Get Health>Promote Health to Variable>Printstring current Health amount
      H key> Get health, minus 10, then set Health with a Printstring showing it chop down
      J key>Cast to ActorWithPassword (plugged in the variable set with G)>ActorWithPassword's Test Function (a Printstring) which succeeds
      I can take out J's Cast To and only plug in the promoted variable to the function and it will work as long as G was pressed first. But Thirdperson's F key doesn't work at all, before or after ActorWithPassword is spawned or pre-existing in the level. I even tried making the default value the ActorWithPassword and still it can't 'see' it through the Object.

    • @aaronhunt7204
      @aaronhunt7204  3 роки тому

      @@PsyCoCinematics J works after G because when you pressed G, you validated the casting object variable. When this variable is invalid, that's why your cast results in a failure. In the instance of your ThirdPersonBP, you need to validate this variable. Either by spawning or setting manually, regardless, that variable needs to be an existing reference to the blueprint you're trying to cast to.

  • @Lothar1812
    @Lothar1812 3 роки тому

    I love you

  • @costa3951
    @costa3951 2 роки тому

    I feel like I know less now then when I started watching.

  • @mobilityrp3888
    @mobilityrp3888 3 роки тому

    This became confusing for me because they changed the way you cast now it doesnt give you the option to select actor class on the left unless you do Get Actor Of Class,

    • @aaronhunt7204
      @aaronhunt7204  3 роки тому

      Hmm, you shouldn't ever need GetAllActorsOfClass for a simple cast. Are you casting to an object or a class?

    • @mobilityrp3888
      @mobilityrp3888 3 роки тому

      @@aaronhunt7204 I'm trying to cast to a class called explosion. This class only exists when spawned by the bomb. So I'm not sure what to assign as the object really

    • @mobilityrp3888
      @mobilityrp3888 3 роки тому

      The explosion is an actor

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

    you explain the problem very well but i don't get why this is the solution

  • @ThanksIfYourReadIt
    @ThanksIfYourReadIt 2 роки тому

    I dont know what cast to is, i dont know why you want to use it and i deffinetly dont know what just happened.

  • @WadeWazenegger
    @WadeWazenegger 2 роки тому

    Everyone using turtle as their password just got really worried.

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

    still not understand a sheet

  • @keelei
    @keelei 2 роки тому +1

    Instead of using cast every time in your game, better try to use interfaces and really learn this kind of topic. You will see you will get much more performance out of the box. Casting is very expensive if you deal with big objects and a lot of references.

  • @vrai_
    @vrai_ 3 роки тому +1

    Get all actor of class
    done

    • @aaronhunt7204
      @aaronhunt7204  3 роки тому +1

      Not a great practice! This method is resource heavy. I recommend against it unless absolutely necessary.

  • @lv99redchocobo37
    @lv99redchocobo37 3 роки тому +1

    still confused lol. sigh. :

  • @assassinhitman
    @assassinhitman 2 роки тому

    I'll never understand casting...just have to do with interfaces

  • @bighit20100
    @bighit20100 2 роки тому +1

    More confused than before...

  • @Broockle
    @Broockle 2 роки тому

    uhh... those nodes have a lot of different colors..

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

      4 months later, same problem again... still don't understand at all 😅
      I just end up putting everything I need into the same actor so I have to cast as little as possible.

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

      godammit i'm here again, everytime!
      Casting is bloody difficult 😆

  • @UnderfundedScientist
    @UnderfundedScientist 3 роки тому

    Seriously amazing stuff, I subscribed.
    If your willing I'd love some feedback on my project, I have a short clip posted

  • @RinoMoen
    @RinoMoen 2 роки тому

    i am even more confused now

  • @Nekro9000
    @Nekro9000 2 роки тому

    Doesnt help with casting from actor to actor though

  • @niranjanwagh5767
    @niranjanwagh5767 3 роки тому +1

    I am very beginner and when I saw what thing you are going to answer, then I got really excited.
    But when you started creating other stuff I started having more questions than answers like what the hell is world blueprint. I having been watching beginner videos for a month now and nobody told what that is! Then the tutorial got more confusing when you bring up widget and parent. And I got more confused between which one is actually a parent and which one is the parent BP we created earlier.
    Please keep things beginner friendly if you are going to explain a beginner level topic.

  • @akillus83
    @akillus83 3 роки тому +2

    To fast man. Look like you wanna go to restroom)))

  • @Pierraxl
    @Pierraxl 2 роки тому +1

    Didn't helped me at all to understand how to correctly cast.

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

    Dude this is why I think I want to start doing tutorials to help people out with things like this because this is absolutely not how you do it and your video didn’t help me at all I sat here for 5 minutes listening to what you said word by word and did it and it didn’t work not one bit what you simply have to do to cast inside of a UI is plug-in player character and that’s literally it

  • @maz5-870
    @maz5-870 Рік тому

    Wasnt very clear on what to do

  • @pacocarrion7869
    @pacocarrion7869 2 роки тому

    Mmmm nice but not clear at all, I think is more complicated than that.

  • @boldganbaatar7023
    @boldganbaatar7023 2 роки тому

    i think its good video. but its not for total beginners!

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

    No error but cast still continuously fails. Bad tutorial

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

    Bruh but why is this shit so f-… complicated

  • @mx-gamesdev8287
    @mx-gamesdev8287 2 роки тому

    For beginers far to fast....

  • @thejoeyfarah
    @thejoeyfarah 2 роки тому

    you confused me way more