Placed actor / spawned actor - Different behavior (no AI possession involved)

Hello guys.

Well, I have a really strange issue, I’m on it for few days now but can’t find out what’s wrong.

To make it simple, I have a kind of spreading unit across actors. It’s like :

ACTOR 1 : (timer loop 0.5s) : push 5 unit to actor 2 → ACTOR 2 : (timer loop 0.5s) : if unit >0 : PUSH unit to actor 3 → ETC

The actor 1 is continuously pushing 5 unit, other are just relay, so in the end of the system I have a continus 5 units arriving.

It works perfectly fine when I place all my actors at run time.

But for some reason, when I place those actors the same way in the viewport, at runtime it is completely out of sync, like : it got 5 unit, push it, the next turn it got 0, and the next time it got 10 units and push 10 units, so the flow become like : 5 / 5 / 0 / 10 / 5

This is happening only for actors placed in viewport and really I can’t determine why … If checked every node, frame by frame with every values, is just seem like irregularly running …

If anyone has any kind of clue, it would really be great and very helpful !

Thank you for reading me.

not sure i exactly understand you but timers on different actors will have different values.

basically meaning they could be out of sync, if that is the problem try having the timer on some manager class and the actors bind to its event

1 Like

Thank you for your answer. I am ok with all my timers beeing not in sync actually, I just need all my timer to run EXACTLY every 0.5 s.

Let’s say the first actor (the one pushing at the origin) arrive at 0.5 : it pushes 5 unit to the actor 2.
And if at this exact moment the actor 2 is at 0.3 of its timer that’s not an issue, when he arrives at 0.5, he checks and see it has 5 units so pushed it, and the next loop he will again have 5 units to push.
Every timers could be Asynchronized, it should work perfectly ( and it does at runtime …)

But after analysing every nodes every frame this is what happens some time :

Normal behavior :

(I’ll refer time as game timeline to understand)

TIME : 0
ACTOR 1 : PUSHES 5 UNITS → ACTOR 2 : NOTHING ACTOR 3 : NOTHING

TIME : 0.5
ACTOR 1 : PUSHES 5 UNITS → ACTOR 2 : HAS 5 UNITS → PUSHES ACTOR 3 : NOTHING

TIME :1
ACTOR 1 : PUSHES 5 UNITS → ACTOR 2 : HAS 5 UNITS → PUSHES ACTOR 3 : HAS 5 UNITS → PUSHES

What seems to happen sometimes only when actors are places in viewport :

TIME : 0
ACTOR 1 : PUSHES 5 UNITS → ACTOR 2 : NOTHING ACTOR 3 : NOTHING
TIME : 0.5
ACTOR 1 : PUSHES 5 UNITS → ACTOR 2 : HAS 5 UNITS → PUSHED ACTOR 3 : NOTHING
TIME : 1
ACTOR 1 : PUSHES 5 UNITS → **ACTOR 2 : HAS 0 UNITS → ACTOR 3 :HAS 10 UNITS

So at line time 0.5, it seems like between step “check if has units” and “push” it receive 5 more units, but that’s not normal at all because it should only arrive at the next loop

I’m sorry its a bit complicated to explain with words and make it clear :confused:

Well, I’ve just solved it …
Explaining it to someone else make me found out ( Rubber duck debugging … )

The only difference for placed actors are that every timers start at the exact same time when the game launch so…

My issue was all my timers beeing rightly exaclty in sync actually … so has evey steps were running at the exact same time for all actors, the code was interposing itself everywhere…

I solved it adding a random time a the begining before timer start, to asynchronise them.

I don’t know how you guys are handling it and if I used the right methode ?

Many nodes and menus have advanced hidden panels, check them out.


We do what @Auran131 mentioned, there is a manager running a timer(s) and broadcasting a dispatcher call to whom other entities subscribe. Rather than running 100 timers, you run 1. Once the bind cost has been paid, the call is somewhat free to make.

1 Like

Thank you for your answer.

Oh I’ve never used event dispatcher yet actually. I’ll deep in the documentation about it, thank you !

But if I use a dispatcher manager, it will call every clients at the same time, and I’ll fall back in my initial problem, no ?

You should not have that problem to start with. This…

[…] for some reason, when I place those actors the same way in the viewport, at runtime it is completely out of sync, like : it got 5 unit, push it, the next turn it got 0, and the next time it got 10 units and push 10 units, so the flow become like : 5 / 5 / 0 / 10 / 5

… is not a thing (yet here we are! :innocent:) under regular circumstances. What is irregular about the rest of the script, is a better question here.


The suggestion about the manager helps with optimisation, maintenance, scalability, debugging and, probably, will not solve the issue since, at least to me, it seems utterly unrelated.

Oh yes alright then…

So I’ll try to keep debugging my first issue. I’ll do the optimisation after.

If I can give a bit more details it’s made like this :

All my actor are the same, but the initial one has illimited internal content. So for each actor :

timer 0.5s loop : If has content : push to next one ( via an interface message)

Interface get content (so whenever it’s called) : add content to internal content

Really that is so strange that it works for placed actors at runtime but not for the one placed in viewport.

Visually it’s like …

debug

The nearest one is placed in game, and the farest one is placed in the viewport :frowning:

Are these particles, what are we looking at?

Yep, particules are there when it push content. When there are nothing it is because the loop before it got twice the content, and nothing the loop after (that is the issue) ( the 5 / 5 / 10 / 0 I was trying to say)

Well with lotsss of breakpoint I’ve confirmed it, in some loop this is what happen :

ACTOR1 (loop) : PUSH CONTENT (message to ACTOR2 )
ACTOR2 → interface called (push content) : add content to internal
ACTOR2 (loop) : Has content ? PUSH CONTENT (message to ACTOR3 )

ACTOR1 (loop) : PUSH CONTENT (message to ACTOR2 )
ACTOR2 → interface called (push content) : add content to internal
ACTOR2 → interface called (push content) : add content to internal
ACTOR2 (loop) : Has content ? PUSH CONTENT (message to ACTOR3 )

ACTOR1 (loop) : PUSH CONTENT (message to ACTOR2 )
ACTOR2 (loop) : Has content ? PUSH CONTENT (message to ACTOR3 )
ACTOR2 (loop) : Has content ? PUSH CONTENT (message to ACTOR3 )

So the call at the interface interpole itself at different moment in the loop each loop, sometimes before the check for content, sometime after the check for content
I guess it is a conception issue … Don’t know how to do it differently i’ll try to find a way

I should implement a kind of queue system.

Is there a way I can delay the code executed by the interfacecall at the end of my loop ? This is exaclty what i need

Are you saying you’re using Loops and Delays? It’s hard to imagine how the script works / flows, not sure we can can help much without understanding what is really happening. Timers themselves are pretty robust by can be misused. If you add delays and loops into the mix, one must tread carefully.


In case you struggle with an angle / approach - do some extra rubber ducking. Or describe it all from the player’s perspective. What are those pipes (?) pumping; and, most importantly, why?

1 Like

Well no i’m not using delays in my loop. But as the code is kind of dense, the interface call is received at different time while the loop is executed, this is my issue.

I made a simulation of fluid propagation inside pipes. The first one with unlimited internal content is in fact a pump yes. But it’s actually a complexe system with temperature balancing etc. It works really perfectly fine in runtime, but for placed actor, every timers start at the same time so the interface call pop sometime exactly in the middle of the next actor loop processing, modifying data beeing proceed. More detailed it’s like

PUMP :
LOOP 0.5 : push content (via message interface) to next PIPE BUFFER

PIPE :
(when push message interface received) : add content to buffer
LOOP 0.5 :
-if internal content >= 0 => push to next one ;
-If buffer >=0 => transfert buffer content to internal content

So the issue is that it’s ok if the call to the interface is adding content to buffer before the start of the loop processing it, but sometime, it has time to be re-called a second time before the loop has ended (that is strange). So If I could delay the interface to add content to the buffer at the end of the loop it should work i guess

thank you for your time @Everynone

Oh gosh seriously, why are my timers loop ( both at 0.5) are running so messy ?? They should run one after the other !! That makes no sense ??

debug

left : actor 1 // right : actor 2

This is totally the source of my problems

Everything is working perfectly fine now … you were right guys @Everynone @Auran131

I didn’t know event dispatcher but it make way more sens now actually. That’s a really usefull lesson learn with a concret case.

Thanks a lot !

I’m still curious why my way doesn’t work, why wasn’t-it running like timer actor 1 / timer actor 2 / timer actor 1 / timer actor 2, as they were configured to run at the same frequence ?

1 Like