SCRIPTING API / Scripts and entities / Scene
Scene
Creates entities in the running scene: empty ones, and instances of prefabs from the project's Content folder. On the dedicated server, instances replicate to clients.
Kindclass
NamespaceKroys.EngineScripting
Members4
Source
Scene.csEXAMPLE
In a script
A complete script that uses Scene; copy it into your scripts project.
Core.cs
public sealed class CrateSpawner : EntityScript { public string Prefab = "Prefabs/Crate.kprefab"; // relative to Content public float Interval = 2.0f; public int Count = 5; protected override void OnStart() => StartCoroutine(SpawnCrates()); private IEnumerator SpawnCrates() { for (int index = 0; index < Count; ++index) { Entity crate = Scene.Instantiate(Prefab, Transform.WorldPosition + new Vector3(0.0f, 2.0f, 0.0f)); if (!crate.IsValid) { Debug.LogError($"Cannot instantiate {Prefab}"); yield break; } Transform.SetParent(crate, Entity); // keep the hierarchy tidy yield return new WaitForSeconds(Interval); } } }
REFERENCE
Members
Methods
#public static Entity Spawn(string name)Creates an empty entity (a transform and a name) in the running scene and returns it.
#public static Entity Instantiate(string contentPath)Creates an instance of a prefab and returns its root, or an invalid entity if that fails. The path is relative to Content, such as "Prefabs/Enemy.kprefab". Scripts on the instance start on the next script update, so its fields are not set up yet on return.
#public static bool SetCharacterModel(Entity character, string modelContentPath)Re-skins an animated character (an entity with Animator and MeshRenderer) with another imported model whose skeleton uses the same bone names. Animations retarget by bone name; extra pieces of the model appear as siblings. False when the model cannot be applied.
#public static Entity Instantiate(string contentPath, Vector3 position)Creates a prefab instance and moves its root to a world position; an invalid entity if that fails.
Signatures
public static Entity Spawn(string name) public static Entity Instantiate(string contentPath) public static bool SetCharacterModel(Entity character, string modelContentPath) public static Entity Instantiate(string contentPath, Vector3 position)
KroysEngine 0.1.0 documentation, built from the engine repository by Tools/BuildDocsSite.py.