"ScenePanel Camera is read-only — configure it in place for 3D previews"
▸ SYMPTOM
You try to set up an in-UI 3D model preview using ScenePanel and assign a new camera:
Camera = new SceneCamera { Position = pos, Angles = ang };This fails with CS0200 — Camera is a read-only property on ScenePanel. The same pattern works in editor Widget code (where Camera is a settable field), which makes the error confusing.
▸ CAUSE
ScenePanel owns its own SceneCamera instance. The Camera property exposes it as get-only — the panel manages the camera's lifecycle internally. Editor widgets use a different base class where Camera is a mutable field, so code copied from editor examples won't compile in a game-side ScenePanel.
▸ FIX
Configure the existing camera in place instead of replacing it. Set its World, Position, Angles, and BackgroundColor directly:
Camera.World = new SceneWorld();
Camera.Position = new Vector3( 100, 0, 50 );
Camera.Angles = new Angles( 15, 180, 0 );
Camera.BackgroundColor = Color.Transparent;Full preview world recipe (matches the engine's own VisemeEditor/Visemes.cs pattern):
// Create the model in the camera's world
var model = new SceneModel( Camera.World, "models/citizen/citizen.vmdl", Transform.Zero );
model.UseAnimGraph = false;
model.CurrentSequence.Name = "idle";
// Light the scene
new ScenePointLight( Camera.World, Vector3.Up * 100 + Vector3.Forward * 50, 500, Color.White );
new ScenePointLight( Camera.World, Vector3.Up * 80 - Vector3.Forward * 30, 300, Color.White * 0.5f );
new SceneCubemap( Camera.World,
Texture.Load( "textures/cubemaps/default.vtex" ),
BBox.FromPositionAndSize( Vector3.Zero, 1000 ) );Advance the animation each frame by calling model.Update( Time.Delta ) in your panel's Tick override. Spin the model by setting model.Rotation each frame.
▸ WHY IT WORKS
The ScenePanel creates and owns one SceneCamera for its entire lifetime. Configuring it in place respects that ownership while giving you full control over the world it renders. The SceneWorld you assign to Camera.World becomes the isolated scene the panel draws — nothing from the game world leaks in, and the preview renders independently in its own UI tile.
- Published