xamarin / urho

Code to integrate with the Urho3D engine
Other
464 stars 122 forks source link

Component's OnUpdate could be executed before Node is attached to a scene #366

Open gleblebedev opened 5 years ago

gleblebedev commented 5 years ago
  1. Create a node in a background thread, add a component
  2. Set ReceiveSceneUpdates = true; in constructor of a component
  3. Add component to a node
  4. await Application.InvokeOnMainAsync to attach the node to a scene
  5. Observe OnUpdate been executed even if the node isn't in a scene.
utekai commented 5 years ago

That doesn't necessarily make it a bug, it just describes how it works.

Once a class is initialized and the constructor set 'ReceiveSceneUpdates = true;' then the OnUpdate method will begin to be called.

If your blocks get knocked around due to this, the simple pattern to handle this issue is to put a boolean in the beginning of OnUpdate that returns if false. Then, once you're all comfortable and you've decided to call OnAttachedToNode, then set your boolean to true, to allow the OnUpdate to proceed.

Your case can be simplified.

Create your component with 'ReceiveSceneUpdates=true' in the constructor, in any thread you wish unless it impacts the ui, then in the main thread. Wait ...

Note that OnUpdate is called. as it should be.

In this provided sample code, the pattern is used to delay updating until long into the sample running.

This implementation offers flexibility to components, they can do a lot of stuff without even being attached to a node ... just imagine.

gleblebedev commented 5 years ago

You see, the name is ReceiveSceneUpdates but the node isn't in a scene. I won't complain if the property would be called ReceiveAppUpdates or something...

utekai commented 5 years ago

When I read 'ReceiveSceneUpdates' all my eyes see is 'x'.

So 'x = true' vs 'y = true' is what you're pushing for? Yes.

I'd like to see NavigationMesh working on UWP. Or networking implemented. Or spatial audio implemented.

There are big important pieces not available. But ok, x to y.


Now, on the other hand, you can have a whole can full of components, all updated, updating, and waiting to be attached to node, like horses ready to bust out of the gate at the racetrack.

Or ... you can call the stable boy, to properly go and prep a horse, walk it over to you, attach it to your node, and then you walk on.

utekai commented 5 years ago

node isn't in a scene

Also, I'm referring to a formal Component, rather than a node. The components, constructed but not node-attached, are part OF the scene, just not IN the scene.

The same way we live in 4D space, but perceive only 3D space. Well, most of us only perceive 3D. Once you attached the Component to a node, it gets projected into visible scene space (assuming it has the right stuff to be visible), and this is relaxing to some who need that sort of comforting.

utekai commented 5 years ago

And ... to add to the list of major not-working features ...

Shadows on UWP. It would be good to be able to see shadows. They work fine on WinForms and WPF, just not on UWP. Hint: It's the hlsl shader.