Comments (3)
@DennisSmolek I have implemented support for ForLoops and Sequences via waiting for downstream evaluation. It works well:
from behave-graph.
Following up,
You would know better than I do (especially because I rarely touch Unreal)
but I was curious about the scenario you described, as it’s similar to common JS for loops being synchronous, thus “waiting”.
I remember all the headaches when things like async http calls became standard and code wasn’t ready for non-blocking..
But all the discussions I’ve found seem to say it’s as I expected and non-blocking:
https://forums.unrealengine.com/t/forloop-is-non-blocking-learn-it-the-hard-way/59127
https://forums.unrealengine.com/t/waiting-for-to-finish-before-continuing-foreach-loop/382460
there’s some stuff about frame execution and a few videos where people create their own to add a delay, but I couldn’t find anything about a “wait”
again I could be totally wrong and just didn’t dig deep enough
from behave-graph.
It is complex.
The problem is that you need to cause the downstream graph from loopBody to fully execute (at least the non-async nodes) before you fire it again. The reason you need to do this is otherwise you could have two loopBodies executing at exactly the same time. Given my current implementation that is a work queue, if you fired them all immediately you would have a series of items immediately inserted into the work queue basically all being the same -- loopBody.
This can not be how Unreal Engine Blueprints work. Because their for-loop construct actually supports "breaking" the loop. In order to support breaking the loop, you can not immediately schedule all loopBody iterations for execution -- or you run into the problem you now need to cancel scheduled tasks, which is basically just the same problem I am trying to solve but in a different way.
I believe that the for-loop node waits for the non-async execution of loopBody before triggering that subgraph to evaluate again. This would allow for one to break the loop. I believe that it doesn't wait across an async node though, like Delay. If you have a for-loop with a delay node in the loopBody subgraph, it will not wait for anything after the delay node.
This is what I was thinking of implementing.
So basically I will support something akin to this:
const startIndex = 0;
const endIndex = 4;
for( let index = startIndex; index < endIndex; index ++ ) {
loopBody( index ); // note: no await here.
}
But just like JavaScript if you add an async call within the loopBody function, the for-loop will not wait for it, but if you avoid async nodes, it will wait for them.
If you put this loopBody into the above for-loop,
async function loopBody( index: number ) {
console.log( `start: ${index}` );
await sleep( 1000 );
console.log( `end: ${index}` );
}
You will get this output:
start: 0
start: 1
start: 2
start: 3
end: 0
end: 1
end: 2
end: 3
But if you put this body into the for loop above:
function loopBody( index: number ) {
console.log( `start: ${index}` );
console.log( `end: ${index}` );
}
You will get this output:
start: 0
end: 0
start: 1
end: 1
start: 2
end: 2
start: 3
end: 3
I am looking to replicate exactly this behavior. I want a standard for loop and if you put in async nodes into it, it will not wait for them.
from behave-graph.
Related Issues (20)
- Proposal - remove class-based node definition, replace with just JSON HOT 4
- Adopt Int32 as the integer type and Float64 as the floating point type. HOT 1
- Improve documentation HOT 2
- Move Scene Profile outside the core package HOT 2
- Update Flow with support for "configuration" on Sequence nodes HOT 1
- Proposal: Add Structured data support HOT 2
- Proposal: support union types HOT 2
- Improved Configuration to Support Documentation and Editors
- Website HOT 5
- Allow for external listeners/emitters for custom events
- Move category and label into metadata fields for node spec.
- Compatible nodes on drag to empty space HOT 1
- Scene node types not available HOT 1
- Move registry out of Flow.tsx into configuration that is passed in. Enables better customization
- Not implemented error and white screen
- opening nodepicker on bottom right of screen breaks background and viewport
- Change ILogger to have only a single function that takes severity and message. HOT 1
- Immutable state is problematic in async nodes like Delay HOT 2
- [Website] set/get variable nodes are not exposed to the React website HOT 1
- npx exec-graph ./graphs/core/flow/Branch.json gives error: '@behave-graph/scene@*' is not in this registry
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from behave-graph.