Jump to content

[SOLVED] World Expressions at Startup


photo

Recommended Posts

Posted

Hello everyone,

A new Unigine Script question, this time I wonder if I stumbled upon a bug.

I was monitoring performance of World Expression use by microprofiling various expressions using the most common operations (getting a node, getting a parent, toggling a surface...) and I stumbled upon a behavior I didn't not anticipate. My nearly empty project contains 1000 sphere node references. The source node has World Expression children, with only one active at a time (the one I'm profiling).

image.thumb.png.e121c809928a569952a187793c70d745.png

 

The last one I added is a toggling surface loop:

{
    Node parent = getNode().getParent();   // Get the signal parent object
ObjectMeshStatic obj = class_cast("ObjectMeshStatic", parent);
int surf = obj.findSurface("sphere");

    float current_time = frac(engine.game.getTime());
    if(current_time > 0.5f)
    {
        obj.setEnabled(1, surf);
    }
else 
{
    obj.setEnabled(0, surf);
}
}

The expression works when active, it's fine. However, when I tried to use one of my other World Expressions by Running the application, I will always find my surface turned off at the beginning. Almost as if this inactive World Expression was executed once at start. If I reopen the editor, I found myself with the same problem: the surfaces are turned off.

So my question is: are World Expressions executed once at startup, even if they are set to inactive in the tree ?

Posted

Hello!

25 minutes ago, K.Wagrez said:

So my question is: are World Expressions executed once at startup, even if they are set to inactive in the tree ?

This is definitely not intentional behavior — we’ve filed it as a bug in our internal tracker and it will be addressed in a future update :)

For now, you can resolve it by adding the following code at the beginning of your World Expression:

Node node = getNode();
if (!node.isEnabled()) return;

Hope this helps and thanks for reporting it!

Thanks!

  • Like 1
Posted

Thanks for the fix, that works for me :)

  • bmyagkov changed the title to [SOLVED] World Expressions at Startup
×
×
  • Create New...