Quick Start Guide
This guide will help you get up and running with the Far Out SDK for Unity in just a few minutes. By the end, you'll be able to display today's Astronomy Picture of the Day (APOD) in your Unity project.
Installation
Via Unity Package Manager (Git URL)
- Open your Unity project
- Go to Window > Package Manager
- Click the + button in the top-left corner
- Select Add package from git URL...
- Enter
https://github.com/extremevisualmedia/nasa-unity-sdk.git
(or the appropriate Git URL once hosted) - Click Add
Via Local Package
If you've downloaded a local copy of the package:
- Open your Unity project
- Go to Window > Package Manager
- Click the + button in the top-left corner
- Select Add package from disk...
- Navigate to the package folder
- Click Open
Setting Up an API Key
The Far Out SDK requires an API key to access NASA's APIs. You can use the DEMO_KEY
for testing, but this has very low rate limits.
- Go to api.nasa.gov and sign up for a free API key
- In Unity, right-click in your Project window and select Create > NASA > NasaConfig
- Select the newly created
NasaConfig.asset
file - In the Inspector, enter your NASA API key
- Click the Test Key button to verify your key works
Creating Your First NASA API Script
Let's create a simple script to display the Astronomy Picture of the Day:
- Right-click in your Project window and select Create > C# Script > NASA Quick Start Script
- Name it
ApodDisplay
and press Enter - Double-click the script to open it in your code editor
The script should look something like this:
using UnityEngine;
using UnityEngine.UI;
using System.Threading.Tasks;
using ExtremeVisual.Nasa;
public class ApodDisplay : MonoBehaviour
{
[Tooltip("Assign your NasaConfig ScriptableObject asset here.")]
public NasaConfig nasaConfig;
[Tooltip("Assign a UI RawImage component here to display the APOD picture.")]
public RawImage apodDisplayImage;
private NasaClient _nasaClient;
async void Start()
{
if (nasaConfig == null)
{
Debug.LogError("NasaConfig not assigned.");
return;
}
// Initialize the NasaClient
_nasaClient = new NasaClient(nasaConfig);
await FetchAndDisplayApod();
}
async Task FetchAndDisplayApod()
{
try
{
// Fetch APOD metadata
ApodData apodData = await _nasaClient.GetApodAsync();
if (apodData != null)
{
Debug.Log($"APOD Title: {apodData.Title}");
if (apodData.MediaType == "image")
{
// Download the image
Texture2D texture = await _nasaClient.GetApodTextureAsync(apodData);
if (texture != null && apodDisplayImage != null)
{
// Display the image
apodDisplayImage.texture = texture;
}
}
}
}
catch (NasaApiException ex)
{
Debug.LogError($"NASA API Error: {ex.Message}");
}
catch (System.Exception ex)
{
Debug.LogError($"Error: {ex.Message}");
}
}
void OnDestroy()
{
_nasaClient?.Dispose();
}
}
Setting Up Your Scene
- Create a new scene or use an existing one
- Add a UI Canvas to your scene (GameObject > UI > Canvas)
- Add a RawImage to the Canvas (GameObject > UI > Raw Image)
- Create an empty GameObject and name it
NasaManager
- Add your
ApodDisplay
script to theNasaManager
GameObject - Drag your
NasaConfig.asset
from the Project window to theNasa Config
field in the Inspector - Drag the RawImage from your Hierarchy to the
Apod Display Image
field in the Inspector
Run the Scene
Press Play! If everything is set up correctly, you should see today's Astronomy Picture of the Day load into your RawImage.
Next Steps
- Check out the sample scenes included with the SDK to see more examples
- Explore the other NASA APIs through the SDK's methods
- Try the Data Explorer window (NASA > Data Explorer) to preview data from the APIs directly in the editor
- Read the configuration guide to learn more about caching and other settings
Troubleshooting
- If you encounter a "Demo API key rate limit exceeded" error, get your own API key from api.nasa.gov
- If the image doesn't load, make sure the APOD for today is an image and not a video (check
MediaType == "image"
) - Check that all GameObject and component references are properly assigned