ambiera logo

Ambiera Forum

Discussions, Help and Support.

folder icon Ambiera Forum > CopperCube > Programming and Scripting
forum topic indicator Restart Scene with Code?
person icon
drnibbert
Registered User
Quote
2026-05-07 20:41:18

Hello!

I just find the "Switch to Scene"-command, but it doesn't restart the scene like the "Restart a scene" Behavior does (i'm already in that scene, so switch doesnt do anything)
How can i do this? :-)

Thanks a lot!

person icon
Guest2
Guest
Quote
2026-05-07 23:40:13

Use the "Restart scene" action before using "Switch to scene".
Like this:
- Restart scene: target scene
- Switch to scene: target scene

Just tried it with 2 simple scenes, switching back and forth between them. Seemed to work (Camera + objects did go back to initial positions).

person icon
Guest2
Guest
Quote
2026-05-09 01:22:42

If you want to do a scene-restart in pure CopperCube javascript, you may need to use a workaround.

The action "Restart a scene" doesn't seem to have a js-function equivalent.

Two workarounds.

Workaround 1:
You could transfer your current script into a scripted action or behavior (.js).

In the script-file header-block comments add:
<property name="my_action_list" type="action"/>

Later invoke the action list in your code:
ccbInvokeAction(this.my_action_list, currentNode);
Or:
ccbInvokeAction(this.my_action_list);

The "my_action_list" would contain:
- "Restart a scene": target_scene
- "Switch to another scene": target_scene

Workaround 2:
You could signal the scene-transition to an object using a CopperCube variable.

- Create a "plane" object (or whatever object you like)
- Attributes: uncheck "Collision", uncheck "OccludesLight", "Scale" = 0,0,0
- Attributes: "Visible" needs to be checked - seems the behavior doesn't work if the object is invisible

- Add a behavior "Every few seconds do something"
- IntervalMS = 250
- Action "If a Variable has a value do something" -> Is LevelSwitch equal to Value 1 ?
- Action list (If condition is true):
- "Set or Change a Variable" -> set LevelSwitch to Value 0
- "Restart a scene": target_scene
- "Switch to another scene": target_scene

To trigger the scene transition, you can now "send a signal" to the object by setting the LevelSwitch-variable to 1.
ccbSetCopperCubeVariable("LevelSwitch", 1);


Further notes:
I have no idea if it is possible to interface the built-in actions via javascript when they are not directly exposed as callable functions. The engine appears to contain internal references to "RestartScene" and "SwitchToScene".

person icon
drnibbert
Registered User
Quote
2026-05-26 08:40:01

Thanks guys! :-) i went with the second aproach and had a "If variable has a value" checking for a variable to be changed! emoji icon_smile

person icon
josh1
Registered User
Quote
2026-06-02 12:45:35

coppercube has a function to do that
ccbSwitchToScene("scene_name");


edit: nevermind... i tried and looks like it doesnt reset the scene


Create reply:










 

  

Possible Codes


Feature Code
Link [url] www.example.com [/url]
Bold [b]bold text[/b]
Image [img]http://www.example.com/image.jpg[/img]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]

Emoticons


icon_holyicon_cryicon_devilicon_lookicon_grinicon_kissicon_monkeyicon_hmpf
icon_sadicon_happyicon_smileicon_uhicon_blink   






Copyright© Ambiera e.U. all rights reserved.
Contact | Imprint | Products | Privacy Policy | Terms and Conditions |