ambiera logo

Ambiera Forum

Discussions, Help and Support.

folder icon Ambiera Forum > CopperCube > Programming and Scripting
forum topic indicator prototype.onAnimate does not work as expected
person icon
Guest of Guest
Guest
Quote
2026-07-22 21:14:11

Ok, I'm trying to change the color of the the directional light which I understand only 1 directional light can exist in the scene.

I have created a small test behaivor script to do this which is loaded and functions as a behavior should.

Below is the snippet of code that is not giving the expected results, from what I understand from the docs should work.


behavior_ChangeSunColorTest.prototype.onAnimate = function(node, timeMs)
{
ccbSetSceneNodeProperty(node, 'Direction', 0,120,-500);
ccbSetSceneNodeProperty(node, 'Color', 1,0,0);
}


I expect the scene light color to change to Red but instead the debug console prints:
Property does not exist: Direction
Property does not exist: Color

The behavior script is attached to the default directional light created within the scene, I've named it sunlight as the name defaults to an empty string.

Now, I would expect as the behavior is attached to the light node then the parameter (node) for the onAnimate function should be set to the light node ?? This does not appear to be the case as I cannot access any of the (node) properties but the node is a valid SceneNode.

Any ideas anyone ??

Thanks.

person icon
hadoken
Registered User
Quote
2026-07-22 23:44:17

Please try this behavior_DirectionalLight.js:

/*
<behavior jsname="behavior_DirectionalLight" description="behavior_DirectionalLight">
<property name="DirectionalLight" type="scenenode" default="" />
</behavior>
*/

behavior_DirectionalLight = function()
{

}

behavior_DirectionalLight.prototype.onAnimate = function(currentNode)
{
ccbSetSceneNodeProperty(this.DirectionalLight, 'Direction', -0.256358, -0.809352, 0.528423);
ccbSetSceneNodeProperty(this.DirectionalLight, 'Color', 255, 0, 0);
}


person icon
hadoken
Registered User
Quote
2026-07-22 23:54:46

If you want multiple directional light sources in your scene:

embedded external image
🔎︎


person icon
Guest of Guest
Guest
Quote
2026-07-23 01:57:06

wrote:
Please try this behavior_DirectionalLight.js:

/*
<behavior jsname="behavior_DirectionalLight" description="behavior_DirectionalLight">
<property name="DirectionalLight" type="scenenode" default="" />
</behavior>
*/

behavior_DirectionalLight = function()
{

}

behavior_DirectionalLight.prototype.onAnimate = function(currentNode)
{
ccbSetSceneNodeProperty(this.DirectionalLight, 'Direction', -0.256358, -0.809352, 0.528423);
ccbSetSceneNodeProperty(this.DirectionalLight, 'Color', 255, 0, 0);
}


Thanks for that, I did resort to that method initially but was not wanting to pass the scenenode as beavior property. I wanted to use the onAnimate node passed that it is attached to, in your example that would be currentNode.

This is how I have always created behaviors, I can't see what the purpose of the onAnimate(node) node parameter is used for ??? Does it not work for directional light nodes ???

Yes, I also know about the Spotlight trick to use more than 1 directional light, thanks.

person icon
guest_Guest
Guest
Quote
2026-07-23 11:26:10

onAnimate(node),

here node is the current node on which the behavior is applied.

in order to use that then you need to use like


behavior_DirectionalLight.prototype.onAnimate = function(node)
{
ccbSetSceneNodeProperty(node, 'Direction', -0.256358, -0.809352, 0.528423);
ccbSetSceneNodeProperty(node, 'Color', 255, 0, 0);
}


so if you are getting property doesn't exist error, then chances are high that you are attaching the extension to another node type you need to attach the extension(behavior) to directional light only, otherwise it will throw that error.

there is also timeMs that you can also use if you want to do time related animations.

person icon
Guest of Guest
Guest
Quote
2026-07-24 02:28:08

Read my full message where I shown the exact code and said:
The behavior script is attached to the default directional light created within the scene, I've named it sunlight as the name defaults to an empty string.

Your code should work but it does not work as expected for the default directional light, it does work for any other node (mesh, terrain etc..) but not for directional light.

I've now see this to be a bug.

person icon
Guest2
Guest
Quote
2026-07-25 04:42:54

The errors mentioned above seem to be caused by a corruption in 2 of the default example files:
terrain.ccb & physics.ccb.

When I use the posted scripts in the 2 examples above, I receive the exact same errors that "Guest of Guest" noted in the initial post.
However, the errors did not occur for me in new "empty" scenes with newly added directional lights.

In both standard example scenes, the name of the pre-added directional light is empty and the light is listed as "(light)" in the scene-hierarchy. This unusual naming could be an indicator of a corruption that was introduced into the two example files at some point.

Workaround:
Replacing the default directional light with a newly created one.
The scripts by hadoken & guest_Guest work without error on newly created directional lights.
For a permanent fix: Replace the lights in the 2 example scenes with new ones, save the files, then copy the modified scenes to the "examples" folder in your CopperCube installation folder & overwrite the original .ccb files.

Further notes:
Looking at the relevant structure in the .ccb file at a binary level (minimal excerpt):

Offset(h) 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
00000290 66 6C 67 68 FF FF FF FF flgh----


Comparing this with working files revealed that the pattern 0xFFFFFFFF after the "flgh" tag seems to trigger the corruption.
Patching the light to a working condition via arbitrarily chosen values (AB CD EF 00) in the .ccb file seemed to work. It will look like this:

Offset(h) 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
00000290 66 6C 67 68 AB CD EF 00 flgh----


If you want to take a risk, you can use a Hex-editor to patch the 2 example files directly. Not recommended. While it worked for me with the example files, I have no idea if this raw patching nonsense introduces any latent problems into the files.
Deeper insight into the structure of the ccb files might reveal why these 4 bytes 0xFFFFFFFF cause the corruption and what these 4 bytes represent.

person icon
Guest2
Guest
Quote
2026-07-26 14:42:44

Exported Irrlicht-scenes (.irr) show that the 4-byte 0xFFFFFFFF value represents an "Id" attribute.
As a signed 32-bit integer, 0xFFFFFFFF represents exactly -1.
Relevant parts from Irrlicht-scene file "<attributes>" section:

Broken directional light:
		
<string name="Name" value="" />
<int name="Id" value="-1" />

Working directional light:

<string name="Name" value="DirectionalLight" />
<int name="Id" value="15715755" />

Based on brief tests: it doesn't seem to matter if the name is empty or not.

The "Id" value of -1 appears to trigger the corruption.

Any project that uses the default directional lights from terrain.ccb & physics.ccb is probably affected by this issue.

person icon
Guest2
Guest
Quote
2026-07-26 15:03:55

The issue affects the Windows/.exe build but does not appear to affect the WebGL build.

person icon
Guest2
Guest
Quote
2026-07-26 20:11:35

Corrections & more info:
- Hadoken's script works on the broken directional light too - and this specific script also has some interesting effects (see further below).
- Script variants using ccbGetSceneNodeFromName() will work as well.
- The number of scenarios where the -1 "Id" issue will negatively affect projects seems to be limited.

The editor-based scene node selection used by Hadoken's script appears to trigger a reassignment of the invalid "Id" (-1) in the editor when the directional light is selected.

Test (using the physics or terrain example):
- Apply Hadoken's script
- Select the target directional light
- Remove Hadoken's script
- Apply the script variant shown by "Guest of Guest" or "guest_Guest"
- Now, test the game.
- Suddenly: ALL variants work. Without replacing the "broken" directional light.

Examination of the resulting .ccb file shows that the "Id" was permanently changed from -1 to a valid Id value.

person icon
Guest of Guest
Guest
Quote
2026-07-29 05:00:27

Guest2 wrote:
Corrections & more info:
- Hadoken's script works on the broken directional light too - and this specific script also has some interesting effects (see further below).
- Script variants using ccbGetSceneNodeFromName() will work as well.
- The number of scenarios where the -1 "Id" issue will negatively affect projects seems to be limited.

The editor-based scene node selection used by Hadoken's script appears to trigger a reassignment of the invalid "Id" (-1) in the editor when the directional light is selected.

Test (using the physics or terrain example):
- Apply Hadoken's script
- Select the target directional light
- Remove Hadoken's script
- Apply the script variant shown by "Guest of Guest" or "guest_Guest"
- Now, test the game.
- Suddenly: ALL variants work. Without replacing the "broken" directional light.

Examination of the resulting .ccb file shows that the "Id" was permanently changed from -1 to a valid Id value.


That's some very in depth findings that you have posted and your tests have certainly found out where the issue is.

My initial tests were using the default templates and like you say, the default light is not registered correctly within the scene. I have now deleted the default light, saved the project and then manually added another light. This now works as expected, with a valid node being passed to the onAnimate prototype function.

Thanks for working on this!

person icon
Guest of Guest
Guest
Quote
2026-07-29 05:09:12

This problem may also exist with other default scene nodes, like sky and terrains as I've noticed a few errors pop up now again for other nodes. Also when refreshing the extensions and plugins list.

At the time I noticed these errors, I simply ignored them as the script would continue as normal and pointed the finger at a poorly coded or incompatible behaviour or plugin.

person icon
Guest of Guest
Guest
Quote
2026-07-29 05:28:31

As Guest2 pointed out, the problem only appears to exist in the two example templates for terrain and physics.

The solution is to directly open these two example template files and manually remove then re-add the directional lights back to the scene. The example files will then need to be saved and overwritten.


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 |