Game Development Community

Question about object instantiation.

by Claude-Alain Fournier · in Torque Game Engine · 05/11/2006 (12:24 am) · 1 replies

Hi all,

I am just getting crazy here. I have a new Console object that I want to be unique, I want only one instance existing in runtime.

This object is instanciated in script within a function.

function initMyObject()
{
        $MyObject = new MyObject() ;
}

In the engine I have the following :

// MyObject is of class  SimObject 

MyObject *gMyObject = NULL ;       // My unique global instance of this object.

// constructor
MyObject::MyObject()
{
	AssertWarn(gMyObject, "MyObject::MyObject : There can be only once instance of this class object !");

	if(gMyObject == NULL)
		gMyObject = this ;	
}

So I have "supposedly" one and one only instance of this object in the whole engine as on the script side I have only ONE call to "initMyObject()".

Now when I start the game and look at the console.log I have multiple warning messages (see AssertWarn) that appear long before initMyObject() call.

I just like to know what's happening here. Does the engine instanciate all class ? Note that MyObject derive from SimObject.

So, who can light my day here ?

Thanks,

CAF

#1
07/03/2006 (5:49 pm)
Posting: Unread posting for more than 30 days. I am posting to help get a reply to your un-answered question.