Make Http Request in Unreal Engine!!!

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
yo welcome back to my channel and in this tutorial we're going to be going over how to make HTTP requests and that's going to allow you to make API calls and all sorts of things now if you don't know what I'm talking about or if you're like what the heck did you just say don't worry it's really cool I'll show you some examples of it right here but it's really cool and it'll take your games to the next level and I just learned it today so I wanted to share with y'all so here let me show you what it does real quick so basically an API allows you to connect one software so my software this game to another piece of existing software out there so some people have written other you know web apps and different kinds of things that do different things and you can you can make those apps talk to each other with API calls and which they are HTTP requests is what they're called so let me show you what it looks like so you got a character here and each one of these things are each one of the blue titles are HTTP requests that I've set up now we can go to this first one here which is random cat facts so this is going to connect you to an API that will spit off random cat texts so watch this wow okay that was oh okay that was a up fact you could press next a cat's vision is about 185 degrees you keep on pressing next and I have it set up in this widget so that you can keep on getting cat facts all day long so that's just one example here here's another example here like random jokes like what if you wanted to hear some random jokes so the same thing how do you organize an outer space party you plan it duh you can get jokes all day you know what I'm saying so that's another thing apis can do for you let me show you another thing that they can do so uh where are we at random dog pictures so not only words but you can do pictures so I've got this widget showing just random dog pictures and when you click next it's going to just show you another dog picture just continuously just gonna keep on going so let's see another example here I got a whole room of these set up and I want to show you guys how to do some of these um this one says how old do you think how old do I think you are so it says type in a name let's type in Jesus 57. um another example that I've got here is a random ideas for boredom right are you bored maybe you can start a book uh you've never gone around to reading and it tells you how many people it's going to take to do that idea and you can get ideas all day long and it'll tell you you know board ideas another one that I set up that was really cool was I tried to combine two of them and I did Kanye quotes with random pictures of pandas in the background I am the head of Adidas I will bring Adidas and Puma back together and bring me and Jay back together yeah yeah um I'll show you that one lasts but this one right here is ask me a yes or no question so and again these are all separate apis these are all separate HTTP requests so if I ask a yes or no question like um is Quinn Channel cool [Laughter] you know I was going to give me an answer is Quinn cool nope I'm guessing not cool guys it's all good well I'm not trying to be cool anyways another thing you could do is like this so you know Dolly right forget Dolly I got my own Dolly so the text to text to image generation right here so I can say what I want to see like how about um uh uh classical picture of a night saving a princess from a dragon bow I press enter and as you see in the middle of my screen is loading right there it's gonna give me an image of what I just typed in boom so that's just like dolly I've got my own Dolly right here so today I wanted to show you guys how I set up most of these and I kind of want to give you a really good understanding of these things uh called API calls and HTTP requests so let's get going the first thing that you'll need to do is go to your Unreal Engine marketplace right go to the the marketplace and search for HTTP request for blueprints once you have that you want to download it because it's free make sure you get this one by this dude right here King way mark that sounds like a that's a cool he sounds like a boss anyways install it to your engine that you're using and then you're gonna have to restart the project that you have you can start a blank project or whatever um or third person project or whatever kind of project you want to start just start that project and then you're going to be caught up to where I am and what I want to show you here is I will make a new API called um right here live and then we'll dive into some of these other complex examples we'll do a simple one first and then dive into some of these complex ones so all right so first things first I want something to happen when I first open or when this level first opens so at the beginning of the level I would do it in the level blueprint and I would do it on the event begin play now don't mind the stuff that I already have here all I have on my event begin play right now on my level blueprint is get player controller set input mode to game only and then set show mouse cursor to false those are like the default things I always put on every level that I do because I mean unless it's like a you want the widget to pop up first so we'll probably change that here anyways all right so now that you've got that HTTP uh blueprint thing what we need to do is we need to figure out how to use it now when I had to learn how to use it I was looking for a video on YouTube and nobody had a video on YouTube and so I guess I'm gonna make a video on YouTube about it or I couldn't find it at least not a short one all right so all you have to do is to make an HTTP request there's a node called make HTTP requests cool once you find that node let's talk about it before we move on so this node is all literally all you will need once you understand this node you have the keys unlocked to you so first things first the execution pin so we can start this you know at the event begin player right after it and same thing with this one now the method this is important now most of the API calls you you'll do they have documentation with them and they tell you how to do what you need to do and most of the time the documentation will have a method uh one of these right here is going to be a git a post to put on one of these right here but most most of the time it's only going to be a git post put or delete I've never seen any of the other ones so a git means you're trying to get information from that uh other software uh put means that you're putting information to that software or you're sending information to that software um post means like you're posting information to that software sort of like uh Dolly I mean yeah and sort of like Facebook you post to your wall um and then delete is just going to delete information from the software you're talking to so git is the most simplest one that I've I've learned right now so it's probably the most common one you're going to be using as well so now that you understand the methods those are the four different methods this is for the URL and every API call has what they call an endpoint and what you do is you type your endpoint or you copy and paste the endpoint URL right here and that's going to tell our software which software to get connected to now sometimes they'll have parameters and you'd have to make parameters sometimes they'll have headers and you'll have to make headers the body is for when you're sending information so when you do a put you would have to fill out something in the body um or a post I'm sorry well no put in post you would have to fill out something in the body because you're sending information but again we'll talk about the get first so after you've got the information sent which in a git you don't even need the byte there is no body in a git um there's an oncomplete and what you have to do from here is create a custom event and we're going to tell what happens after this call is created or after it's completed so I'm still maybe talking like jibber jabber for y'all but I'm gonna make it clear watch there's a website that allows you to practice with apis and if you just go to this website right here um it's epiphany dot IO it has a list of free apis that you can play with so I say we play with one right now why not okay let's start with one that I've I did already called cat facts and this this is pretty simple so basically it's saying that you can get a random cat fact via text message every day but it doesn't have to be text message we can just set this up so that it just gives us random cat facts as you saw in the um as I showed you in the example so basically this is the URL right here that is going to take us that we need copy that paste it so you can see what it looks like there you go all right so you copy this right here and paste it to a new browser and this is what it looks like so this is all the information that we need so what is this telling us right here we have the URL that we're going to use and remember that we'll plug the URL into the URL and then right here it shows us the structure of the things that we're going to need so this is all anything that's written in quotes it means it's a string right so this is all a string this length is a string but the number return right here is not a string it's a number it's not written in quotes so right what we need to do is take this information and plug it into that node so that's what we're going to do right now so the first things first is that URL let's go ahead and get that same URL which is right here at the top catfact dot ninja slash fact copy that and paste that and we want to do a git because we're trying to get this fact from this this this cat fact thing so we're gonna do keep that git method as get now for the parameters and the headers if we go back and look at the cat thing there are no parameters and there are no headers we can certainly use we can we can alter this around and make it have some parameters if we wanted to but literally there's no doesn't need any in that case with this node all you have to do is drag off your parameters and say make a map right and it's going to give you a key and a value when you do have to use parameters you're going to have to fill out the key and the value but in this case we don't need that so we can delete them or we can remove right click and remove key value pair this is going to give us an empty map and we need the map to be empty or we need something there in order to go forward so for me I'm just going to keep it empty I'm going to copy and paste that and I'm also put my headers as an empty map so nothing there all right since this is a git and it's not a put or we're not like posting anything um then we don't need a body but here's the cool part what we do need is on complete so every time on complete just drag off of it and create a custom event this is every single time the custom event is called the response or the Callback like basically when we get this information from this URL it's going to give us a response and from here we can tell this response what to do now here's how you handle most of the API calls that you'll be doing the response will come back in a form called Json pretty much or you want it in Json so from your response drag off and say to Json it's right there at the top two Json hook up the response string now you've got your response and it's in Json format which we can do a lot with that format now that we have this part set up what we need to do next is we need to go back and look at this so we're looking at this uh on the website you know so we type this into the web browser and it gave us this and we see that it says fact this pretty much colon means equals so fact equals cats can predict earthquakes blah blah blah blah blah blah so basically we want to know the fact and then there's another one called length which we don't really need the length so we'll just say we want the fact and the way that you get this fact is you have to get a string because you see that it's in quotation marks so this is how we'll do that from your two Json node drag off and say git string I told you this was way simpler than you think plug the Json to Json right and for the string it's asking us for a key well what part of the string in that response do we want and this is where you'll get this right here this is the key fact that's the that's what we want we want the fact so that will be our key so facts boom just type it in as it is you can copy and paste it as well but now that you have that string there the response is going to come back to as a Json and we're going to get from that Json the fact out of that now we need to do something with the fact and because I'm on my because I'm on the level blueprint we can like let's create a widget right let's create a widget to display this fact so after get string type create widget and then we can add it to the viewport but we don't have a widget yet so let's create one real quick so in your content browser right click user interface widget blueprint user widget and we can call it uh cats underscore WB so make sure that this is now pointing at your cats perfect all right let's go to our cats let's actually open that that widget that we just made now we gotta really quickly create a widget so I'm not going to spend too much time explaining this but I'm just going to do it as quickly as I know how to get a canvas panel right click it wrap it with a scale box wrap it with a size box turn your size box to you know whatever resolution you want to I'm using 1080 1920 by 1080. then on your canvas panel we need to put you could put a background picture if you want to so just get an image and drag it there put it on the whole screen and then zero it out zero zero zero zero and then change the image to whatever color you want the background to be so I want mine to be black boom and then we want the cat fact to go there so let's put a text block and usually for my text block I always try to size it you know is a good size and then there's a button down here called auto wrap that's what you really want to click for this it's right here wrapping auto wrap text click that make sure you're text block is in the middle of your screen with the anchor all right cool so now we've created this widget and now we have something to do so in our third person map in our level blueprint after we've created this widget we can actually move this to the top here so hold alt to break this link and we're going to move the create widget and add to viewport up here and that's fun but after this print string what we need to do is we need to cast to our third person character because there we need to set some variables so the variables that we need to set is fact we need to make a fact variable so go to your third person character or whatever character you're using go to the event graft and create a variable called fact I'm just trying to make sure I don't have one already all right and then that variable make it into a string compile and Save now the only reason why we did that is because we need to store this value in somewhere that we can recall it and I figure the player character is pretty easy for that so from your git string let's cast it a third person character and you know get player character oops that can't spell anyways get player character and then we're going to set that set facts right here so what are we going to set the fact to we're going to set it to this string here boom and now when we make that HTTP request the fact will be set to the string that comes from the Json that comes from the response so with that set fact let's go ahead and create this um on this widget let's go ahead and make it a little bit better so our text block right now it says text block and we can change that here but instead of changing it let's just bind it so create a binding drag off this and we're going to say third person character so cast your third person character and get player character and then what we want to do is we want to get that string that we just made which was called facts so get fact and plug it right on into the return node just like that so basically this text block should return back a cat fact for us so let's make sure that it's correct there by checking this it's set as a fact boom boom okay now we need to hook this up to the beginning so let's hook it up to right after I set the mouse cursor Actually I don't even want this right here let's take that off let's take that off just hook it up to begin play and begin play and then on the end I'm going to get player controller and then I'm going to set the input mode to UI only and which UI I'm gonna do it to this UI and then I'm gonna set the mouse cursor show mouse cursor to true so when it begins plays it's going to show this widget but what's going to be on the widget is this response here so let's compile and Save and when we press play it should have a cat effect in white text on a black background so let's check that out play cat family is usually play best even in numbers cats and kittens should be acquired in pairs whenever possible perfect so that's how you make an API call it's very simple but I'm not gonna leave you hanging there I mean in mind there's a way that you can press next and get another cat fact so let's go ahead and set that up real quick so I'm going to save all because this is Unreal Engine 5 and they have a little bug but anyways the way we're going to set up this cat fact thing let's open up our level blueprint and let's look at that widget that we just created so this one let's put a button called Next here so make a button put in the bottom right corner or wherever you want it and just put some text on it that says like next or a new fact or something like that all right so when the player clicks that button we need a new fact to pop up on that screen the way we're going to do that is press on pressed or on clicked whatever one is your preference and here's what we gotta do so on clicked we need it to make another HTTP request so what I would do is go back to your um a local blueprint pretty much copy this and this just copy the first you know part of this so your HTTP requests your parameters your make map for your headers response and the Json and that'll be a good starting point copy and paste that and we'll hook that up so when they press that button we wanted to make another HTTP request to this URL cool and pretty much it's going to give us a response that's good we're going to turn that response into Json we're going to get a string so and remember the string that we want is fact cool now that we got that string we need to set same thing it's the exact same thing we just want to set it just like we did here set the fact for the third person character so just copy and paste so all it's doing is cast into the third person character getting the player character setting facts as facts right here hook that string in and that will give you a new fact because it's going to do another HTTP request you don't have to put anything after this because all we're doing is setting the variable here which in turn will change this fact so let's make sure that works by pressing play when a domestic cat goes after mice about one pounds and three results in a catch okay yep see if you click next next next next next next next thing about all the facts about the cats so that's how you set up an HTTP request told you it wasn't that hard you can do all kinds of things with this um including creating your own text to image software your Dolly type software all the documentation is out there for you all you have to do is look it up but now you have the tools to use it and you have some at least some you know a good starting point if you have any questions you could probably reach out to me I'm not saying I'll have the answer but I'll try um and yo I hope you learned something hope you enjoyed this and to end this video I guess what I'll do is uh let's unhook that node and I want to leave you guys with uh Kanye West quote Okay so to end this video let's go ahead and get a Kanye quote the Kanye quote we get is buy property and that's what it is I'll holla at y'all next time peace
Info
Channel: Quinn Anthony
Views: 6,681
Rating: undefined out of 5
Keywords: Q&A, Quinn Anthony, unreal engine, unreal engine 5, http request in unreal, api calls in unreal engine, API, API unreal, UE5, Get, put, request, http request with blueprints, free api test site, videogames, gamers
Id: Lkzy8GqPSkY
Channel Id: undefined
Length: 27min 16sec (1636 seconds)
Published: Sat Feb 18 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.