Cover for the App

Studio: Spawning System

Studio

This project demonstrates how to dynamically spawn 3D entities using a custom component in Niantic Studio.

This project demonstrates how to dynamically spawn 3D entities using a custom component in Niantic Studio.

Spawning System Sample Project

This project demonstrates how to dynamically spawn 3D entities using a custom “spawner” component in Niantic Studio. You’ll learn how to:

  • Automatically load and place multiple instances of a 3D model into the scene.
  • Configure spawn settings such as entityAmount and spawnSpeed.
  • Use simple ECS state machines to coordinate asset loading and event transitions.

Description

The Spawning System Sample showcases a “spawner” component that periodically creates new 3D entities (e.g., cows). Each spawned entity is given a model, basic animation, a collider, and a random position near the camera. This setup demonstrates how Niantic’s Entity Component System (ECS) can handle multiple objects’ creation and initial configuration on the fly.

Project Structure

Below is a brief overview of the key folders and files:

.

├── assets/ // Additional media assets (the cow.glb model)

├── spawner.ts // Main script defining the Spawner component

└── README.md // This README file

Key Files

    • Defines the component, which controls how many entities to spawn, at what interval to spawn them, and how to position them.
    • Uses a simple state machine to handle the “loading” phase (spawning entities) and a final “done” state once all objects are created.

Hierarchy Entities Overview

  • Spawning System Entity

    • An entity that has the component attached.
    • Configures references for how many entities to spawn () and the delay between spawns ().
  • Spawned Entities (Cows)

    • Automatically created during the spawner’s LOADING state.
    • Each one receives:
      • GltfModel (the cow model).
      • ScaleAnimation (scaling up from 0.1 to 1).
      • Collider (cylindrical shape).
      • A random position near the active camera.

How It Works

  1. Spawner Component

    • Registered in . The ECS references two key properties:
      • : Number of entities to spawn.
      • : Milliseconds between spawns.
  2. State Machine

    • LOADING (initial): Iterates up to , creating a new entity at intervals of .
    • Each spawned entity loads a cow model, attaches a ScaleAnimation, and sets its Position and Collider.
    • After the loop finishes, a trigger transitions to the DONE state.
  3. Random Positioning

    • For each entity, a random x-coordinate (between -4 and 4) is chosen, while the z-position is offset behind the camera.
    • The y-coordinate is slightly above the ground.
  4. DONE State

    • Once all entities are spawned, “all done!” is logged. You can use this state to run additional logic, such as re-triggering the spawns or toggling UI elements.

Getting Started

  1. Clone or Import This Project

    • Open Niantic Lightship Studio and import or clone this sample project into your workspace.
  2. Assign the Spawner Component

    • In the Scene view, create/select an entity and add the component from your project’s Scripts panel.
  3. Configure in Inspector

    • Use the entityAmount field to set how many 3D models you want to spawn.
    • Adjust the spawnSpeed (in milliseconds) to control how quickly each model appears.
  4. Preview

    • Press Build or Publish.
    • Observe the new entities (cows) spawn near your camera, one by one, until the total is reached.

Customization

  • Model & Animation

    • Change the in if you want a different .
    • Modify the or remove it for a static model.
  • Collider Shape

    • Try different types (e.g., , ) to experiment with collisions or physics behavior.
  • Spawn Pattern

    • Adjust the random offsets in to spread entities differently.
    • Change or at runtime to create more dynamic experiences.
  • Additional Logic

    • In the DONE state, you can add extra steps (e.g., display a “spawn complete” UI, trigger a special animation, or re-run the spawner).

Troubleshooting

  • Entities Not Appearing

    • Ensure is correctly attached to an entity with the component.
    • Verify that the file is present in the folder and that the path matches.
  • Spawning Too Fast or Slow

    • Adjust the value in the Inspector to suit your needs.
  • Colliders Not Working

    • Make sure the newly spawned entities have valid settings.

Enjoy floating cows and exploring how to dynamically spawn 3D models in your Niantic Studio projects!