SpawnObject (Unity)

- Declaration

public static string SpawnObject(this CavrnusSpaceConnection spaceConn, string uniqueIdentifier, Action<CavrnusSpawnedObject, GameObject> onObjectCreated = null)

-public static string SpawnObject(this CavrnusSpaceConnection spaceConn, string uniqueId, Vector3 pos, Action<CavrnusSpawnedObject, GameObject> onSpawnComplete = null)

-public static string SpawnObject(this CavrnusSpaceConnection spaceConn, string uniqueId, Vector3 pos, Vector3 rot, Vector3 scale, Action<CavrnusSpawnedObject, GameObject> onSpawnComplete = null)

- Description

Instantiates the given object with no set properties.

Note: to make a prefab spawnable you will first need to create the prefab and designate it as spawnable and assign it a UniqueIdentifier. This string is what the journal will use to indicate which object should be spawned.

This UniqueIdentifier will then be passed in as the only parameter of SpawnObject.

It will then synchronously return the ContainerName of the newly spawned instance, which can then be used to post properties for the newly spawned instance. Without any posted properties, its transform will default to being at the origin with 1x scale and rotation zeroed out.

Note that versions of SpawnObject exist which take in a transform. Under-the-hood, these simply call SpawnObject, followed by a PostTransformPropertyUpdate. They are just a useful shortcut.

- Sample

using CavrnusSdk.API; using UnityEngine; public class SpawnObject : MonoBehaviour { private CavrnusSpaceConnection spaceConn; void Start() { CavrnusFunctionLibrary.AwaitAnySpaceConnection(spaceConn => this.spaceConn = spaceConn); } public void SpawnNpc() { if (spaceConn == null) Debug.LogError("Cannot spawn object, not yet connected to a space"); string npcContainerName = spaceConn.SpawnObject("NpcPrefabUniqueID"); //Flip the object 180 degrees and place it at the origin spaceConn.PostTransformPropertyUpdate(npcContainerName, "transform", Vector3.zero, new Vector3(0, 180, 0), Vector3.one); } }

Â