Simple Object Spawner
Enable a preset object at a spawn point when interacted with.
Category: Utility Tools
UdonSharp Script
using UdonSharp;
using UnityEngine;
using VRC.SDKBase;
using VRC.Udon;
public class SimpleObjectSpawner : UdonSharpBehaviour
{
public GameObject objectToSpawn;
public Transform spawnPoint;
public override void Interact()
{
VRCPlayerApi localPlayer = Networking.LocalPlayer;
if (localPlayer == null || objectToSpawn == null || spawnPoint == null) return;
Networking.SetOwner(localPlayer, objectToSpawn);
objectToSpawn.transform.SetPositionAndRotation(spawnPoint.position, spawnPoint.rotation);
objectToSpawn.SetActive(true);
}
}
Setup
- Place an inactive object in scene (
objectToSpawn). - Create empty transform as
spawnPoint. - Add this script to a button with
VRC_Interactable. - Assign references.
Notes
- This pattern is for pre-placed objects, not runtime prefab instantiation.
- Add a paired reset script for repeated interactions.
Extra Tips and Troubleshooting
Tips and Tricks
- Use one spawn location per object type to reduce confusion.
- Pair spawner with a reset/cleanup button for repeat sessions.
Troubleshooting
- If object appears in wrong place, verify spawn transform rotation and parent hierarchy.
Related Content
Prefab Setup Notes
Import the prefab or script into a throwaway test scene before adding it to a live world. Confirm inspector references, ownership behavior, sync, triggers, UI hooks, and audio or object links before moving it into the production scene.
Testing Checklist
- Test once as a local player and again with a second client or late joiner if the behavior can affect more than one player.
- Confirm ownership, sync, trigger zones, UI references, and audio or object references are assigned intentionally.
- Check desktop and VR interaction distance so players can actually use the feature in context.
- Keep a backup of the scene before changing prefabs, UdonBehaviours, or serialized references.
