I created scene in the editor and try to load it. I have followed AngelScript file, that does not want to work.
First, I load the scene like this
[code] SharedPtr file = g_pApp->GetConstantResCache()->GetFile(levelResource);
m_pScene = new Scene(context_);
m_pScene->LoadXML(*level);
m_pCameraNode = m_pScene->CreateChild("MainCamera");
m_pCameraNode->CreateComponent<Camera>();
// Set an initial position for the camera scene node above the plane
m_pCameraNode->SetPosition(Vector3(0.0f, 2.0f, -10.0f));
SharedPtr<Viewport> viewport(new Viewport(context_, m_pScene, m_pCameraNode->GetComponent<Camera>()));
m_pRenderer->SetViewport(1, viewport);
[/code]
- Then I have followed action script, which attachedto the object. All work fine, until I pressed space, in order to create prefab and try to set initial impulse.
[code]class Cannon : ScriptObject
{
if (input.keyDown[KEY_SPACE] && shootDelay <= 0.0f)
{
shootDelay = 1.0f;
Shoot();
AnimationController@ animCtrl = node.GetComponent(“AnimationController”);
animCtrl.SetTime(“Models/Shoot.ani”, 0.0f);
animCtrl.PlayExclusive(“Models/Shoot.ani”, 0, false, 0.0f);
}
}
void Shoot()
{
Vector3 position = node.GetChild("CannonballPlace", true).worldPosition;
XMLFile@ xml = cache.GetResource("XMLFile", "Objects/Cannonball.xml");
Node@ newNode = scene.InstantiateXML(xml, position, Quaternion());
RigidBody@ body = newNode.GetComponent("RigidBody");
body.ApplyImpulse(node.rotation * Vector3(0.0f, 1.0f, 0.0f) * 15.0f);
}
}[/code]
When I try to InstantiateXML, my program crashed and I have the following output.
ERROR: Scripts/Cannon.as:47,13 - Exception ‘Null pointer access’ in 'void Cannon::Update(float)'
AngelScript callstack:
Scripts/Cannon.as:void Cannon::Update(float):47,13
I have checked that all path are correct.
How I can fix it ?