Stupid question: loading scene

I created a basic scene with the editor and now Im looking in the samples and doc how to load it in my project, but cant find the way. Can somebody explain me how to do it?

Say you save your scene as XML, then you can simply load it as follows (C++):

ResourceCache* cache = GetSubsystem<ResourceCache>();
scene_ = new Scene(GetContext());

You can also load from binary data in a similar fashion.

Is there any other step required to display it? I load the scene, no errors in the log, but cant see anything, no matter where I place the camera.

I’m assuming you’re basing your code off of some of the Urho samples, but do you have a light in your scene? You are also attaching a camera to the scene, right? such as:

cameraNode_ = scene_->CreateChild("Camera");

Yes, I have a directional light and Im creating the camera, first tried creating camera in editor, and then in the code (using the same coordinates I tested in the editor, except for the rotation). Neither way I can see the scene.

Hard to tell at this point, but I’m thinking that you might want to eliminate problems by using existing code that you know is working, and then trying to add your code there, e.g. use the StaticScene sample as template (as this is very basic to start with): … taticScene

I load scene like this, it is a sync mode,

String sceneFileName(“GameData/Scenes/sceneTest.xml”);
String sceneFileName(“GameData/Scenes/sceneTest.bin”);
SceneMgr *mgr = GetSubsystem();
String sceneFileName(“GameData/Scenes/scene”);
sceneFileName.AppendWithFormat("%d.xml", mgr->GetLevelSelected());
sceneFileName.AppendWithFormat("%d.bin", mgr->GetLevelSelected());
File scenedata(context_, GetSubsystem()->GetProgramDir() + sceneFileName, FILE_READ);

SharedPtr sceneFileXml(new XMLFile(context_));
scene_ = new Scene(context_);
scene_ = new Scene(context_);
#endif // LOAD_XML_SCENES[/code]


When creating the camera, you need to bind it to a Viewport to display anything.

Here’s my code for setting up a MainMenu scene off an existing XML file:

	// Load the scene and script files
	_scene = new Urho3D::Scene(context_);
	Urho3D::SharedPtr<Urho3D::File> sceneFile = GetSubsystem<Urho3D::ResourceCache>()->GetFile("MainMenu.xml");
	_script = GetSubsystem<Urho3D::ResourceCache>()->GetResource<Urho3D::ScriptFile>("");

	// Setup scene

	Urho3D::Script* script = GetSubsystem<Urho3D::Script>();

	// Setup camera and viewport
	_cameraNode = new Urho3D::Node(context_);
    Urho3D::Camera* camera = _cameraNode->CreateComponent<Urho3D::Camera>();
    // Set an initial position for the camera scene node above the floor
    _cameraNode->SetPosition(Urho3D::Vector3(0.0f, 3.0f, -20.0f));

	Urho3D::SharedPtr<Urho3D::Viewport> viewport(new Urho3D::Viewport(context_, _scene, _cameraNode->GetComponent<Urho3D::Camera>()));
    GetSubsystem<Urho3D::Renderer>()->SetViewport(0, viewport);

This code loads a scene from XML as well as a default script file (To run the scene logic as a script). Then I create a camera node (Created outside of the scene so that it isn’t deleted during network replication), setup a viewport to bind the scene and camera, then set this as the primary viewport.

For completeness, MainMenu.xml is actually just a re-named NinjaSnowWar.xml (From Data/Scenes) that can be changed out later. If you’re interested to see how the script works, here is

UIElement@ buttonContainer;
Button@ startButton;
Button@ multiplayerButton;
Button@ characterButton;
Button@ settingsButton;
Button@ exitButton;

void Start()
    XMLFile@ uiStyle = cache.GetResource("XMLFile", "UI/DefaultStyle.xml");
    // Set style to the UI root so that elements will inherit it
    ui.root.defaultStyle = uiStyle;

    buttonContainer = ui.root.CreateChild("UIElement");
    buttonContainer.SetFixedSize(graphics.width, graphics.height);
    buttonContainer.SetPosition(0, 0);
    buttonContainer.layoutMode = LM_VERTICAL;

    startButton = CreateButton("Start");
    multiplayerButton = CreateButton("Multiplayer");
    characterButton = CreateButton("Character");
    settingsButton = CreateButton("Settings");
    exitButton = CreateButton("Exit");

    SubscribeToEvent(startButton, "Released", "HandleStart");
    SubscribeToEvent(multiplayerButton, "Released", "HandleMultiplayer");
    SubscribeToEvent(characterButton, "Released", "HandleCharacter");
    SubscribeToEvent(settingsButton, "Released", "HandleSettings");
    SubscribeToEvent(exitButton, "Released", "HandleExit");

Button@ CreateButton(const String& text)
    Font@ font = cache.GetResource("Font", "Fonts/Anonymous Pro.ttf");
    Button@ button = buttonContainer.CreateChild("Button");
    Text@ buttonText = button.CreateChild("Text");
    buttonText.SetFont(font, 24);
    buttonText.SetAlignment(HA_CENTER, VA_CENTER);
    buttonText.text = text;
    return button;

void HandleStart(StringHash eventType, VariantMap& eventData)

void HandleMultiplayer(StringHash eventType, VariantMap& eventData)

void HandleCharacter(StringHash eventType, VariantMap& eventData)


void HandleSettings(StringHash eventType, VariantMap& eventData)


void HandleExit(StringHash eventType, VariantMap& eventData)

However the script is completely optional.

How can I adapt this to load the camera from the scene file? I think it is easier to locate and rotate the camera there.