Why do setattrib and set an attribute behave differently?

   699   2   1
User Avatar
Member
7 posts
Joined: Dec. 2016
Offline
I notice when I try to set a group or attribute via one of the set*groupor setattribfunctions, the changes won't reflect in my code.

if(@ptnum == 0){
    setpointattrib(0, 'test', 1, 100);  // The first point changes the 'test' value for the second point
}

/*
None of the statements become true after this, even if
the test attribute on the second point is supposed to be 100.
*/

if(i@test == 100){ // For the second point, we should step to this statement and print out the ptnum and the value
    string result = sprintf("%d : %d, ", @ptnum, i@test);
    printf(result);
    printf('\n');
}

if(point(0, 'test', 1) == 100){ 
    string result = sprintf("%d : %d, ", @ptnum, i@test);
    printf(result);
    printf('\n');
    
}

But when I do the check on a second wrangle after this one, the statements become true, and I get the results:
if(i@test == 100){ // For the second point we should step to this statement
    string result = sprintf("%d : %d, ", @ptnum, i@test);
    printf(result);
    printf('\n');
}

if(point(0, 'test', 1) == 100){ 
    string result = sprintf("%d : %d, ", @ptnum, i@test);
    printf(result);
    printf('\n');
    
}

1 : 100, 0 : 0, 1 : 100,
What's the difference between these two methods of setting an attribute, and is there any way to enforce a setattribfunction to affect the outcome of the wrangle node where I used it?"

Attachments:
setattrib_example.hiplc (111.2 KB)

User Avatar
Member
9416 posts
Joined: July 2007
Offline
set*attrib() functions are queued and always write to output geometry after all other code in a single thread serially

So you can't access modified values in a single wrangle

One of the reasons is that the elements are not executed in any specific order but in parallel, so they can write/read in place only attributes for the current element through @ binding

But there are probably other technical reasons
Edited by tamte - March 3, 2025 03:02:09
Tomas Slancik
CG Supervisor
Framestore, NY
User Avatar
Member
696 posts
Joined: Aug. 2019
Offline
affect the outcome of the wrangle node where I used it?

Very generally speaking, you don't do this in Houdini. Using several wranglers is the norm.

The reason is that Wranlger has some magic behind it: it runs in parallel, which means the order of read/write is nondeterministic if it changes the attributes in place.

You can imagine that when you use setattrib, Houdini actually writes the new attribute value to a copy of your geometry, not the one you can read from with @attrib.

Using the second wrangler is the proper solution. It's not a hack.
Edited by raincole - March 3, 2025 03:01:22
  • Quick Links