Skip to content
NP Editor Docs
This is not the latest version — view the latest

Scene access and play camera

SDK 1.3 adds two things. host.Scene reads scene actors (cameras · paths · trigger zones · displays …), and host.View reads the play state and clock and moves the viewport camera during Play. With these you can build camera work such as orbits, zooms and path following in the Play preview. Write "sdk": "^1.3" in plugin.json.

Typing myorbit in the console creates a camera that circles (0, 70, 0) for 6 seconds during Play.

  1. In Register, register a command, PlayChanged and PlayTicked.

    double t = 0; bool on = false;
    host.AddCommand(new NpCommand("myorbit", "myorbit", "6-second orbit camera during Play", _ =>
    {
    if (!host.View.Playing) return "Not playing";
    on = true; t = 0; return "Started";
    }));
    host.View.PlayChanged += playing => { if (!playing) on = false; };
    host.View.PlayTicked += dt =>
    {
    if (!on) return;
    t += dt;
    var c = new NpVec3(0, 70, 0);
    var eye = new NpVec3(c.X + 30 * (float)Math.Cos(t), 85, c.Z + 30 * (float)Math.Sin(t));
    host.View.LookAt(eye, c, fov: 60);
    if (t > 6) { on = false; host.View.ReleaseCamera(); }
    };
  2. Build, then click Reload (selected) in the Plugin Manager.

  3. Click the Play button (▶) on the main toolbar to start Play (Alt+P).

  4. Type myorbit in the Console. The camera circles for 6 seconds and then returns to the original view.

  • Once moved, the camera stays where it is. Create motion by calling SetCamera · LookAt every tick in PlayTicked.
  • Place a scene camera actor (camera) and read its position and angle with host.Scene.Find("<id>"), and you can line up shots by eye in the editor.
  • Actors reads the world again on every call. Do not call it every time inside PlayTicked; read it once on PlayChanged(true).
  • If you stop Play during a shot (Esc), the editor returns the camera to the original view and sends PlayChanged(false). Clean up your state there.
  • The built-in action cinematic already handles multiple cameras, paths, holds and moves. If you register the same type with AddSceneEvent, it collides with the built-in type and the plugin does not enable, so for your own camera work, do not register a type; use only Scene · View.
MemberTypeDescription
ActorsIReadOnlyList<NpSceneActor>All actors (in Outliner order). Each call returns a copy freshly read from the current world.
Find(string id)NpSceneActor?Find by id. null if not found
public sealed record NpSceneActor(string Id, string Kind, string Name, NpVec3 Pos, NpVec3 Rot, NpVec3 Size, string PropsJson = "{}");
FieldDescription
IdActor id (the name world logic uses)
KindKind (camera · path · trigger · blocker · display · text · spawn · light · particles · sound …). Block actors are included too, so filter by Kind.
NameName shown in the Outliner
PosPosition (world coordinates, one block = 1)
Rot(yaw, pitch, roll) in Minecraft degrees
SizeBox size for actors that have a box, such as trigger zones and blockers; otherwise the size scale
PropsJsonProperty object as a JSON string. "{}" if none
  • This is the authored state, not a pose moved by animation during Play.
  • Read PropsJson with System.Text.Json. Examples: a camera’s fov, a path’s points (world coordinates [[x,y,z],…]).
foreach (var a in host.Scene.Actors)
if (a.Kind == "camera") host.Log($"{a.Id} {a.Name} {a.Pos} yaw {a.Rot.X} pitch {a.Rot.Y}");
if (host.Scene.Find("route") is { } path)
{
using var doc = System.Text.Json.JsonDocument.Parse(path.PropsJson);
if (doc.RootElement.TryGetProperty("points", out var pts)) host.Log($"{pts.GetArrayLength()} path points");
}
ValueMeaning
yaw 0Faces +Z (south)
yaw 90Faces −X (west)
pitch 0Horizontal
pitch 90Faces down

These are the same rules as the angles on the Minecraft F3 screen. NpSceneActor.Rot and the angles of INpView use the same rules.

MemberTypeDescription
PlayingboolWhether Play or Simulate is running
PlayTimedoublePlay clock (seconds). Starts at 0 and stops while paused. 0 when not playing
CameraPosNpVec3Current camera position
CameraYaw · CameraPitchfloatCurrent camera angles (Minecraft degrees)
CameraFovfloatCurrent field of view (degrees)
SetCamera(NpVec3 pos, float yaw, float pitch, float fov = 0)boolMoves the camera to that position and direction. true on success
LookAt(NpVec3 target, float fov = 0)boolLooks at target from the current position (where this plugin last put the camera)
LookAt(NpVec3 eye, NpVec3 target, float fov = 0)boolLooks at target from eye
ReleaseCamera()voidReleases this plugin’s camera control (back to the original view)
PlayChangedevent Action<bool>?Play started (true) · ended (false)
PlayTickedevent Action<double>?Every tick of the play clock (0.05 seconds). Value = elapsed seconds
RuleDetails
When it worksOnly during Play or Simulate. Otherwise it returns false and does nothing.
MotionOne call leaves the camera at that position. To move it, call it every tick in PlayTicked.
First-person bodyWhile the plugin moves the camera, the first-person body stops.
fov0 or less = keep the current field of view. Other values are clamped to 30–110 degrees.
Invalid valuesAn infinite or NaN position, or a LookAt whose eye and target are the same, returns false
RestoringOn ReleaseCamera(), Play stop, plugin disable or isolation, the camera returns to the original view (Play = the body’s eye position, Simulate = free camera) and field of view.
Several controllersUses the same path as the built-in action cinematic preview. If several move the camera in the same tick, the last one wins.

An example that zooms with a scene camera actor:

double zt = 0; bool zoom = false; // start with zoom = true from a command or similar
host.View.PlayTicked += dt =>
{
if (!zoom) return;
zt += dt;
var cam = host.Scene.Find("cam_zoom_1");
if (cam == null) { zoom = false; return; }
host.View.SetCamera(cam.Pos, cam.Rot.X, cam.Rot.Y, fov: 70 - (float)zt * 5); // zoom by narrowing the field of view
if (zt > 6) { zoom = false; host.View.ReleaseCamera(); }
};
  • PlayTicked is called every 0.05 seconds. Keep it light.
  • Camera work is for the editor preview. The camera on the game server is handled by the server plugin.
  • There is no API for creating or moving scene actors. They are read-only.