Changing scenes and scripted components.

Editor
Feb 18, 2010 at 7:49 AM

so. im changing scenes to reload new levels, and i have a property on one of the components that im using to do this.

the property is BlocksRemaning its an int. when you destroy a block it reduces by one, and when that count is 0 the engine switches scenes to the next level

and should reset the value to its original to start the next level.

However, it doesnt seem to work. im using

playerProps = Engine.GetScript<BatScript>("Bat");     

and then

playerProps.blocksRemaining = 14; to reset the number of blocks, the first level switches fine but the second one doesnt

the new scenes have the BatScript - ed object in them too.

when reloading a scene with the same named scripts in it, do the properties pass over into the new scene or will i have to create the "bat" outside of the scene editor ?

Thanks.

Bubzy.

Editor
Feb 18, 2010 at 7:52 AM

posting on the forum seems to have made me come up with a solution, that i GetScript the new bat after loading the scene. seems to work ok. let me know if this is a bad way of doing it. LoadDocumentHook doesnt seem to happen with each new scene, is this intentional?

Coordinator
Feb 18, 2010 at 8:11 AM

You should likely create the bat in a totally separate document that is loaded only once or create it outside the scene editor, say in the game script.

LoadDocumentHook is only called once for each object instance since each object instance is loaded only once. Just because you have two perfectly similar objects in separate documents doesn't mean they're going to be the same instance. For example, if you load the same document twice at the same time, you will have two instances of the all the objects in the document (which is not likely what you would want).

Cheers!