Search by Algolia
Introducing new developer-friendly pricing
algolia

Introducing new developer-friendly pricing

Hey there, developers! At Algolia, we believe everyone should have the opportunity to bring a best-in-class search experience ...

Nick Vlku

VP of Product Growth

What is online visual merchandising?
e-commerce

What is online visual merchandising?

Eye-catching mannequins. Bright, colorful signage. Soothing interior design. Exquisite product displays. In short, amazing store merchandising. For shoppers in ...

Catherine Dee

Search and Discovery writer

Introducing the new Algolia no-code data connector platform
engineering

Introducing the new Algolia no-code data connector platform

Ingesting data should be easy, but all too often, it can be anything but. Data can come in many different ...

Keshia Rose

Staff Product Manager, Data Connectivity

Customer-centric site search trends
e-commerce

Customer-centric site search trends

Everyday there are new messages in the market about what technology to buy, how to position your company against the ...

Piyush Patel

Chief Strategic Business Development Officer

What is online retail merchandising? An introduction
e-commerce

What is online retail merchandising? An introduction

Done any shopping on an ecommerce website lately? If so, you know a smooth online shopper experience is not optional ...

Vincent Caruana

Sr. SEO Web Digital Marketing Manager

5 considerations for Black Friday 2023 readiness
e-commerce

5 considerations for Black Friday 2023 readiness

It’s hard to imagine having to think about Black Friday less than 4 months out from the previous one ...

Piyush Patel

Chief Strategic Business Development Officer

How to increase your sales and ROI with optimized ecommerce merchandising
e-commerce

How to increase your sales and ROI with optimized ecommerce merchandising

What happens if an online shopper arrives on your ecommerce site and: Your navigation provides no obvious or helpful direction ...

Catherine Dee

Search and Discovery writer

Mobile search UX best practices, part 3: Optimizing display of search results
ux

Mobile search UX best practices, part 3: Optimizing display of search results

In part 1 of this blog-post series, we looked at app interface design obstacles in the mobile search experience ...

Vincent Caruana

Sr. SEO Web Digital Marketing Manager

Mobile search UX best practices, part 2: Streamlining search functionality
ux

Mobile search UX best practices, part 2: Streamlining search functionality

In part 1 of this series on mobile UX design, we talked about how designing a successful search user experience ...

Vincent Caruana

Sr. SEO Web Digital Marketing Manager

Mobile search UX best practices, part 1: Understanding the challenges
ux

Mobile search UX best practices, part 1: Understanding the challenges

Welcome to our three-part series on creating winning search UX design for your mobile app! This post identifies developer ...

Vincent Caruana

Sr. SEO Web Digital Marketing Manager

Teaching English with Zapier and Algolia
engineering

Teaching English with Zapier and Algolia

National No Code Day falls on March 11th in the United States to encourage more people to build things online ...

Alita Leite da Silva

How AI search enables ecommerce companies to boost revenue and cut costs
ai

How AI search enables ecommerce companies to boost revenue and cut costs

Consulting powerhouse McKinsey is bullish on AI. Their forecasting estimates that AI could add around 16 percent to global GDP ...

Michelle Adams

Chief Revenue Officer at Algolia

What is digital product merchandising?
e-commerce

What is digital product merchandising?

How do you sell a product when your customers can’t assess it in person: pick it up, feel what ...

Catherine Dee

Search and Discovery writer

Scaling marketplace search with AI
ai

Scaling marketplace search with AI

It is clear that for online businesses and especially for Marketplaces, content discovery can be especially challenging due to the ...

Bharat Guruprakash

Chief Product Officer

The changing face of digital merchandising
e-commerce

The changing face of digital merchandising

This 2-part feature dives into the transformational journey made by digital merchandising to drive positive ecommerce experiences. Part 1 ...

Reshma Iyer

Director of Product Marketing, Ecommerce

What’s a convolutional neural network and how is it used for image recognition in search?
ai

What’s a convolutional neural network and how is it used for image recognition in search?

A social media user is shown snapshots of people he may know based on face-recognition technology and asked if ...

Catherine Dee

Search and Discovery writer

What’s organizational knowledge and how can you make it accessible to the right people?
product

What’s organizational knowledge and how can you make it accessible to the right people?

How’s your company’s organizational knowledge holding up? In other words, if an employee were to leave, would they ...

Catherine Dee

Search and Discovery writer

Adding trending recommendations to your existing e-commerce store
engineering

Adding trending recommendations to your existing e-commerce store

Recommendations can make or break an online shopping experience. In a world full of endless choices and infinite scrolling, recommendations ...

Ashley Huynh

Looking for something?

A Tale of Two Engines – Algolia & Unity
facebookfacebooklinkedinlinkedintwittertwittermailmail

A search engine inside a game engine? It’s an idea that took shape just before one of Algolia’s off-sprint days, an event where Algolians experiment with new concepts.

During the previous off-sprint, my colleague Samuel Bodin and I were thinking: Algolia has a .NET API Client, and Unity supports C# as a scripting language–Why not try to bring them together?

Our idea was to implement a search-as-you-type experience inside a Unity game scene. We decided to create a marketplace, a common use case for searching within a game.

The result? Success. Except for a small challenge with performance, which was solved by switching into asynchronous mode, at the end of the day we had a fully functioning Algolia search within Unity, complete with an index of game assets and images, and a full search and results UI. Let’s see how this was done!

Using Algolia with Unity. Getting started!

Unity does not support the .NET package manager NuGet. To address this, you have to download the zip package of the Algolia library directly on nuget.org, and then unzip the contents in the Assets/Plugins folder of your Unity Project.

After that step, you have to add the using Algolia.Search.Clients; statement in a C# script to start using Algolia with Unity.

Now that we have Algolia plugged into Unity, the next step is to create the game scene.

Finding Assets

Our first task was to find game assets and a dataset to craft our game scene.

We found this excellent starter kit from Unity and used it as a foundation for our experiment. The good thing is, it was packed with a lot of UI elements–we just had to reuse them to create the marketplace scene and add a menu to access it!

Creating a dataset of planets

Before digging into the game design, we had to create a dataset. Since science-fiction was the theme of the assets, we decided to create a dataset composed of planets. We created a thousand fake planets with a powerful dataset generator, Mockaroo. We then used CC images to illustrate the dataset. Once that was done, we were ready to go! If you want to reuse the data you can find it on GitHub.

Crafting the marketplace

The final and most challenging step was to create the game scene for the marketplace. We wanted it to be simple: it would be composed of a search bar and a panel displaying the results. To achieve this, we took the controls scene from the starter kit and customized it. The result—a panel for the planetslooked like this:

After scaffolding the scene, a little bit of work was required to bring it to life. We needed to script some C# to turn the empty box into planets.

Scripting the as-you-type search

Before sending requests to Algolia, we needed to catch every keystroke the user was typing. To achieve this, we attached a C# script to the InputField to catch the ValueChangeCheck() event. All good, we were able to retrieve the input keystrokes! Making a request to Algolia with the retrieved string was as simple as:

var results = await _searchIndex.SearchAsync(new Query(SearchInput.text)
{
    HitsPerPage = 8,
});

Note: we had already instantiated the AlgoliaClient and the Index object in the Start() method to avoid creating a client for each request.

We got the search working, and Algolia’s C# API returned a list of planets (List<Planet>). Now we had to display them. We had to create GameObjects.

We wrote the void LoadResults(List<planets>)method, which creates game objects from List<Planet>. You can find the source code on GitHub. Here we will point out only a few parts. In short, the method loops on the planets to create game objects, one for each planet.

Perfect.

No, not perfect. Not yet: the display of planets was too slow, and the image refreshes were choppy.  

Asynchronicity

Our first idea was to create two game objects per planet: a RawImage and a Text, and then to do some computations to position them in the scene. The search experience was OK, but it was a bit laggy.

So we looked into this and discovered a flaw in how we displayed the planets. We were loading the planets’ textures synchronously, and that’s what made it seem slow. The solution to make the search experience more fluid was to load the planets’ textures asynchronously. To achieve this, we used the Resources.LoadAsync<Texture2D> method from Unity in our LoadTexture

IEnumerator LoadTexture(RawImage image, Planet planet)
{
    var resourceRequest = Resources.LoadAsync<Texture2D>($"{planet.Path}"); ;
    while (!resourceRequest.isDone)
    {
        yield return 0;
    }

    image.texture = resourceRequest.asset as Texture2D;
    image.color = Color.white;
}

You can see the difference in the video below:

Perfect! But not done. While the search experience was fast enough for our POC, we had not yet loaded the scene from the main menu.

Loading the scene from the main menu

To close the loop, we created a button in the main menu to access the marketplace. We attached a LoadSceneOnClick script onto the OnClick() event of this button. This script, as its name implies, loads a scene with its index after the button is clicked:

public class LoadSceneOnClick : MonoBehaviour
{
    public void LoadByIndex(int sceneIndex)
    {
        SceneManager.LoadScene(sceneIndex);
    }
}

We now have all the pieces in place, so let’s see the result!

Are we done?

In one day, we created a simple marketplace in Unity with a search powered by Algolia’s C# API client. And we are not finished! One interesting direction is to try the same with other game engines; for example, another project would be to reproduce this integration with CryEngine, which also supports C# as a scripting language!

But the real next step is to add all of Algolia’s features into the solution. There are still a lot of possibilities for us to explore: creating a search in an inventory in MMO games, adding a UI to search servers, adding facets and filtering, deepening the dataset, adding analytics and personalization, etc. Essentially, as your game increases in complexity, your marketplace, and any search-based feature in Unity, will need to follow suit. Happy gaming!

Written in collaboration with Samuel Bodin.

About the author
Antoine Hemery

Senior Software Engineer

githublinkedintwitter

Algolia documentation

It's extensive, clear, and, of course, searchable.

Read the docs
Algolia documentation

Recommended Articles

Powered byAlgolia Algolia Recommend

Deploying Algolia to Search on more than 2 Million Products
algolia

Maxime

10 great search productivity tools built by our developers
engineering

Peter Villani

Sr. Staff Writer

Redesigning our Docs – Part 6 – The processes and logistics of a large scale project
algolia

Maxime Locqueville

DX Engineering Manager