How To Create a 3D NFT Asset and Render It in Unity

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey everyone in this tutorial I'm going to show you how to create 3D Assets in unity create them as nfts and how to render them back in unity we're first going to create a 3D object in unity we're going to create an asset bundle out of it and then we are going to go ahead and store that asset bundle in ipfs which we will then create an nft with after that we will take our nft and we will render it back into Unity that way whenever the game loads it will check our smart contract to see the nft and it'll go ahead and render it back into Unity so let's go ahead and get started and let's jump right into Unity so I'm going to open up Unity Hub here and what we're going to do is create a new project I'm going to create a 3D project and I will go ahead and name this then we'll just go ahead and name this third web Unity go ahead and create the project all right and once it's created it will open up a Unity for us now the first thing we're going to do is go ahead and set up third webs SDK with unity you can go ahead and head on over to the unity SDK and download the latest Unity SDK package we'll go ahead and add a link to this down in the description I already have it downloaded but you can go to right below here under assets and download this third web Unity SDK package right here so back in unity what we're going to go ahead and do is under assets we're going to import package custom package and we're going to select that third web Unity SDK we're gonna go ahead and open and we're going to go ahead and hit import and let's go ahead and before we get started we will go into our file under build settings and we will set this all up so for platform we're going to select web GL here we're going to switch our platform we're going to go to player settings under resolution and presentation we'll go ahead and select third web and under other settings we'll go ahead and check uncheck Auto Graphics API now under our scenes to build we're going to be building off this sample scene right here so we'll go ahead and add our open scene which is our sample scene and I'm going to go ahead and close this for now what we're going to do is create a 3D object so I'm going to go ahead and create a 3D object we're going to create just a cube for this example so if I scroll in here you can see this is our 3D object which is this Cube and that is going to be our nft that gets rendered on to our scene here now we're also going to create an empty and this empty is what we'll go ahead and render the object once it reads our nft from our smart contract so first thing we need to do is create an asset bundle for our Cube here and basically what asset bundles are is they will load on runtime that way what it's going to do it's going to check our smart contract and then bring in the nft that we specify so what we need to do first is create an asset bundle and what we're going to have to do here is in our assets folder we need we're going to write a script here that is going to create an asset bundle for us so we're going to go ahead and create a c-sharp script here and we're just going to name it create asset window dot CS then we'll go ahead and we'll open up our create asset bundle file we just created we're going to go ahead and get rid of this code here and we're going to go ahead and add our code to add our our build asset bundle menu option so what we're doing here is we're creating a menu item that is going to build the bundles for us and it's going to then create a folder for us called asset bundles that is going to go ahead and generate the asset bundles that we need and what we're going to do then is take that file and upload it to our ipfs and create an nft from it so what you'll see here is now under our assets we now have the menu option to build an asset bundle now before we do that we do need to create a prefab out of this Cube here and to do that you can just come up to our hierarchy here grab the cube and drag it into our project assets folder right here now you can go ahead and name it what you want we're going to leave it Cube and what we'll do is go ahead and select our prefab here and on the right side under our inspector at the very bottom we have our asset bundle so we're going to assign an asset bundle to it we're going to create a new one and we're going to call it test bundle so once we have that created and selected we'll come back up to our assets here and we'll go ahead and click build asset bundles so again what that'll do is under our assets here it will build an assets bundle folder and it'll go ahead and create the files that we need to upload to our ipfs to create our nft all right now once it's done again in our assets under the assets bundle folder you should see these files here that it went ahead and created for us so now what we're going to go ahead and do is upload our test bundle file to our ipfs and we'll go ahead and create an nft using that so let me go ahead let's open up our terminal here and again we're going to first switch over and change directory to our asset bundles folder here so I'm just going to switch over to our what did I call it right so once we are in our asset bundles folder we can double check by doing LS just check that our test bundle file is there and once we go ahead and see that we are in the correct directory we'll go ahead and upload our file to our ipfs so we're going to use third web CLI to do this so we're going to do MPX third web at latest and we're gonna do upload and what we're going to do is upload our test bundle and what that will go ahead and do is upload our file to ipfs and it will go ahead and give us our IPOs URI which we are going to use to create our nft so the next thing we need to do now is create our nft so first we're going to go ahead and create our nft collection smart contract so if we head on over to thirdweb's dashboard we're going to go ahead and deploy a new contract here we're going to scroll down to the nfts and we're going to select nft collection we're going to go ahead and deploy that and we'll just call this Unity 3D assets and I'll just call give it a symbol and then These are 3D Unity assets for this example on the chains I'm going to select the growly test net and then we're going to go ahead and hit deploy go ahead and confirm that transaction all right and our smart contract for our nft has been deployed so we don't have any entities yet but now let's go ahead and mint our nfts to our smart contract so what we're going to do is we're going to use a template here to help us upload this so the template we're going to use is MPX third web we're going to create using a template and it's going to be the 3D asset nft script so go ahead and create that template for us we'll just call this 3D asset script great and we'll go ahead and change directory to our 3D asset script and we'll go ahead and open this in vs code so with that open if we come up to our stories here and our index.ts you can see we have this templated code for us to use let me just zoom in a bit so all we need to do is update the values up here and we'll go ahead and run this and it will go ahead and upload our nft from our ipfs that we just that we created earlier and it will mint that nft to our contract so first thing we need to do is get our smart contract address so if you come back to our dashboard here up in the top left of our smart contract you can just copy that address we'll go ahead and replace it there our network is gorily so we're just going to get rid of the optimism here our private key what we're going to do first is go ahead and create a new file uh dot EnV file and we are going to go ahead and store our private key in here now we don't recommend storing your private Keys like this there are more secure ways for securing your private key but for this example we're going to just store it in a DOT EnV file if you do want to learn more about how to secure your private key it'll be down in the description below and we do have some guides on that so I'm going to go ahead and put our private key right in here okay and then the last thing we need to do is our ipfs for the test bundle that we went ahead and uploaded so we come back to our terminal here and we scroll up we can see this is where our ipfs is we'll go ahead and copy that and we'll replace it with this one here now next you can see down here what it's going to do is it's going to go ahead get our contract which is an nft collection and it is going to go ahead and mint to our collection using uh the name that we put here so we'll just call this 3D cube and then our description and then our image which is going to be our ipfs URL which is what we had put up here earlier and if that mints successfully we should go ahead and see that it successfully minted so next we need to go ahead and run this so we'll open up our terminal here and we'll do npx TS node and we'll go ahead and run our index.ts file so once we do this we should wait it'll be a little bit and we should see it has successfully minted our nft and there you go you can see we have successfully minted our nft so if we head out to our third web dashboard it should load our nft which is our 3D cube that we just created and then the last thing to do now is back in unity we're going to go ahead and render this nft right here into Unity into our scene when the game loads so back in unity here what we're going to do first is create a new folder in our assets so create a new folder we'll call it scripts and in that scripts folder we'll go ahead and create a new c-sharp script again and we'll name it web3.cs and what we'll do is this Cube here we no longer need because this cube is going to get rendered when we load our game so we're going to get rid of that this game object right now it is at empty this game object here is but we'll go ahead and render our cube with this web 3 file we just created we'll go ahead and click and drag that over our game object what that will do is if we cut our game object here is it links that script to that object so again this game object is what is going to load the nft that we select so we'll go ahead and open up that web3.cs file here and we'll go ahead and get rid of this code so in our web 3 script here what we're going to do is we're going to create so that when our Unity scene loads it is going to one check our third web SDK it's going to load our nft and go ahead and spawn our nft into our scene now the first thing we need to do for our load nft function here is we need to go ahead and store our contract so we can use the get Contract function here to go ahead and we'll put our contract address which is of our nft collection that we just created we're going to go ahead and get our nft which was token ID 0 so depending on the nft that you're looking to get you're going to go ahead and get and put in that token ID there and then the asset bundle is going to be the metadata that we went ahead and stored which was that test bundle and we're going to go ahead and return that asset bundle URL next we need to go ahead and spawn that nft into our scene so we're going to make sure that we Define the prefab name which should match the name if we go back to Unity here should match the name of the prefab that we created here so whatever it's named should match this name name right over here next we're going to go ahead and request the asset bundle from the ipfs so again using that asset bundle that we went ahead and got from our nft smart contract and if something failed with a request we'll go ahead and get our network error or error and if successful we'll go ahead and again using that game object we're going to load our asset to it and that game object will go ahead and render our Cube so if we come back to our Unity here now what we're going to go ahead and do is under file we're going to build and run our Unity scene here again our scene does not have our cube in it but once the game loads and checks our smart contract it will go ahead and load our Cube under this game object here so we'll go ahead and build and run and once our game scene has loaded you can see right here we have our Cube so if I refresh this real quick see once we reload it it's not here at first and then it is rendered into our game scene with our game object so there you have it that's how you can go ahead and create 3D Assets in unity upload them to ipfs using third web create nfts with it and then using that nft smart contract render your nft back into Unity so I hope you folks enjoyed this tutorial if you did enjoy it give this video a thumbs up hit that subscribe button and until next time see ya
Info
Channel: thirdweb
Views: 4,029
Rating: undefined out of 5
Keywords: 3d nft art, 3d nft generator, 3d nft blender, 3d nft card, 3d nft card blender, 3d nft animation video, 3d nft animation, 3d nft card after effects, 3d nft drawing, 3d nft character design, 3d nft procreate, 3d nft design, 3d nft blender tutorial, 3d nft carachter design
Id: H14NpyvQCdg
Channel Id: undefined
Length: 14min 54sec (894 seconds)
Published: Thu Jan 05 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.