- Generating images in unity using midjoureny through userapi.ai
-
This Unity script provides an interface to communicate with the Midjourney API for generating and upscaling AI images based on user input. Here's a summary of its functionality:
-
User Input & Button Interaction:
- The script links a user input field (
TMP_InputField
) and a button (Post
) in the Unity UI. - When the button is clicked, it sends the text prompt entered by the user to the Midjourney API.
- The script links a user input field (
-
API Requests:
- Send Post Request: Posts the input prompt to the Midjourney API for image generation. It includes a webhook URL to track the progress of image generation.
- Check Image Status: Repeatedly checks the status of the image creation until it's either done or an error occurs.
- Send Upscale Request: Once the image is generated, the script randomly selects one of the four images and sends an upscale request to enhance the selected image.
-
Webhook and Progress Tracking:
- The webhook is used to receive updates on the image generation progress. The script continuously checks the status of the image until it's fully processed.
-
Image Download and Display:
- Once the image is upscaled and finalized, the script downloads the image and displays it on a Unity
RawImage
UI component.
- Once the image is upscaled and finalized, the script downloads the image and displays it on a Unity
This script integrates API calls with Unity's
UnityWebRequest
system to interact with external APIs and updates the Unity UI dynamically based on the API responses. -
- Make an account in userapi.ai
- Follow THIS Blog to setup & connect to your MidJourney API.
- Setup Webhook to expose endpoints, I prefer Webhook.site (Easy) and assign webhook variable in below code.
- Enter all the Kyes and URL from userapi.ai Dashboard in the code provided below in this repo.
- All the base code is provided in the CODE
- Callbacks Used:
- POST
- GET
- Callbacks Used:
- Check out the doc for ferther implimentations - Read Doc.
- Enjoy 😌!