[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
I learned something new, but it did not solve my problem.
I have never seen such a perfect description of coding.
He went wayyy too fast, showing off way too much that he’s good at what he does but not really explaining
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!
Lol yea he goes so fast it seems hes talking to himself.
@@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.
@@Zeriel00 try slowing video down, it helps but makes him sound drunk.
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
Yeah this is a super confusing way to explain this concept. Weird approach to use widgets.
Great video. I love how you are building repport with us by relating to the errors.
OMG I love you. I have been struggling for 3 days trying to get this to work. You're awesome!
Thank you, this is great, This is exactly what I was looking for!
I've been trying to figure this out for the past 2 hours, then i saw this and you saved my life. Thanks man
This is the first video i've seen that actually explains casting in a understandable way. Great video
Thank you for this great explanation!
Thank you so much! This was very helpful.
I just want to say thank you very much! You re awesome! Cant thank you enough
Finally, I got the answer after weeks of searching... God Bless you man
maaan, thank you A LOT!!!! this video is exactly what i was looking for, is a solution for my problem!
Thank you so much! You fixed my problem. Its sad how you only have 66 subscribers. Here brother, have a sub
damn, this video is a lifesaver. thanks!
exelent !! 🙌🙌 I saw a lot of tutorials but this is the best, you won a like and suscriber sr
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.
Interfaces ...
Where is a vid that explains the name of this alternative?
JAJAJA Thank you so much ! This video makes me happy!
I haven't tried it yet but it looks like its what I needed. will edit tomorrow but THANK YOU!!
Thank You! I was your 160th Subscriber
Well Explained thank you so much
This is brilliant! This has fixed my problem, thank you!
hi @Jessica Marina Rushie , I think this helped me also
Perfect pace and clear explanation! Thank you. Subscribed!!
Thank you. Your video will very helpful for me;)
Easy, Fast & Pro. THX MAN
thank you:)very helpful
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.
thanks a lot! , but how to bind events of a button in widget, inside an actor blueprint? like an actor to widget communication.
Very nice!!!!!
GRAN VIDEO, MUY BUENA FORMA DE EXPLICAR
4:42 I have been looking for that answer for... ever... LOL Thanks
Thanks for solving my problem
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 :)
Best way for Refferences: Cats or A LOT OF CATS
.
.
Man, you Deserve More Sub !!!
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.
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
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!
Thank u a lot!
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
thank you!!
Hey! Thanks a lot for the video! And if we work with an actor, where can we get a reference for an object?
yes
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...
awesome but what if i have a Boolean in that class that i wish to change its value from a different BP what then?
when i create widget and add parent it doesnt has a object(selection)
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).?
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.
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.
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.
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.
A successful cast will return the desired object reference, meaning you can set your boolean value using the "As (Your Class Name)" pin.
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
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!
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.
I'm trying to cast a blueprint with mesh to a widget. or the versa....and I'm lost somewhere.
working without error but for example it doesnt work with integer.. the default integer value doesnt not make changes
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
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..
You're the best
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.
1:34 Your goddamm right
yeah 100%
Can you do one where I’m casting to an NPC to either follow or not follow me?
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.
how do you cast to landscape?
Wow do i find it soo funny that you made the password turtle 😂😂😂
thanks
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
I have the same problem so if u found the solution i would appreciate an explanation
@@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.
@@ChaseTheVase thanks so much It worked!
I will try this tomorrow. Bjt tutorial kind a fast to me.
How to cast to "Get Class Display Name" ?
Had to watch at .25x speed a few times, but good info
It helped but is that really the only way to get object i feel not!.
2:32
I was having trouble getting object reference in the widget until I looked it over again and this part i
Thank god for youtube's slowdown function
i love you
I would have avoided so many stressful moments if I knew you could do that 2:50
2:38 Tick Expose On Spawn
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?
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. 😄
@@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?
@@PsyCoCinematics Casting is the same everywhere. What is in your object pin?
@@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.
@@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.
I love you
I feel like I know less now then when I started watching.
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,
Hmm, you shouldn't ever need GetAllActorsOfClass for a simple cast. Are you casting to an object or a class?
@@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
The explosion is an actor
you explain the problem very well but i don't get why this is the solution
I dont know what cast to is, i dont know why you want to use it and i deffinetly dont know what just happened.
Everyone using turtle as their password just got really worried.
still not understand a sheet
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.
Get all actor of class
done
Not a great practice! This method is resource heavy. I recommend against it unless absolutely necessary.
still confused lol. sigh. :
I'll never understand casting...just have to do with interfaces
More confused than before...
uhh... those nodes have a lot of different colors..
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.
godammit i'm here again, everytime!
Casting is bloody difficult 😆
Seriously amazing stuff, I subscribed.
If your willing I'd love some feedback on my project, I have a short clip posted
i am even more confused now
Doesnt help with casting from actor to actor though
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.
To fast man. Look like you wanna go to restroom)))
lmao
Didn't helped me at all to understand how to correctly cast.
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
Wasnt very clear on what to do
Mmmm nice but not clear at all, I think is more complicated than that.
i think its good video. but its not for total beginners!
No error but cast still continuously fails. Bad tutorial
Bruh but why is this shit so f-… complicated
For beginers far to fast....
you confused me way more