Archive 17/01/2023.

Updating controls in Angel Script

Bananaft

So in NinjaSnowWar.as controls are updated during Update and then assigned to a player controlled ninja. Ninja.as uses this controls during FixedUpdate.

What if I want to use some controls in regular update? For example mouse look is better to be handled during regular update. How can I ensure that main script will be updated before any other objects? Because otherwise there will be one frame lag.

Is there other good ways to handle controls in script?

Also, I just noticed that Ninja Snow War uses:
SubscribeToEvent(gameScene, "SceneUpdate", "HandleUpdate");
While all other samples use:
SubscribeToEvent("Update", "HandleUpdate");
Why it’s so? And what is the difference?

jmiller

Hi Bananaft,

SubscribeToEvent() has overloads to subscribe to events sent by a specific Object, e.g.

SubscribeToEvent(node_, E_NODECOLLISION, URHO3D_HANDLER(Character, HandleNodeCollision));

E_UPDATE is the application-wide variable timestep update event you know.
On E_UPDATE, the Scene sends E_SCENEUPDATE (Urho3D/Scene/SceneEvents.h) only if the scene is enabled.

*edit: I have a CameraController that sets controls in E_UPDATE while CharacterController sets them in E_SCENEUPDATE. Maybe not the best way if there could be a frame lag?

HTH

Bananaft

Hi, thank you for reply, @jmiller.

I did some tests with frame number logging. Fascinating finding, If my main game script subscribes to plain update, it happens last in the frame, after all other objects already updated. If it subscribes to scene update, just like Ninja Snow War does, update happens first in the frame. But I’m not sure If I can rely on this order, since I was able to squeeze player’s update before it, by creating player object before subscribing game script to this events, also disabling and reenabling components changes this order.

Are they query input subsystem both by they own or doing something like NinjaSnowWar? If first, there can be no lag.

jmiller

Ah, yes, my Controller objects are replicated like NSW. Thanks for the findings.