ZakBlystone / gmod_blueprints

Blueprint Editor for Garry's Mod (Visual Programming)
GNU General Public License v3.0
59 stars 9 forks source link

V2: Entity Initialize event triggers twice #76

Open Reginald-Halifrax opened 4 years ago

Reginald-Halifrax commented 4 years ago

First of all, let me go ahead and say thank you so much for the addition of switch cases, I was the one who requested it, Twitchy Tristan from the discord. They make things so much easier, again; amazing response time.

Unfortunately I have a bug to report:

Whenever you spawn an entity created by blueprint the initialize event triggers twice, depending on context this isn't always an issue, however; in use cases such as getting a random value and/or a random entry from a table, the result can change.

Say for instance you want to spawn an entity and set it to some random model from a table, then play a sound related to the model. You will unfortunately find that the sound played (obviously after init) may only sometimes be the correct sound, by dumb luck.

The easiest way to reproduce this issue is simply by passing a print directly after initialization.

However: if you were to put any and all your nodes after the node, the issue disappears as it seems Server only suppresses the double call.

Hope that this was of any use, keep up the good work!

ZakBlystone commented 4 years ago

When entities initialize, that function is called on the server and client. This might be what is causing your issue. Have you tried putting a "ServerOnly" node directly after "Initialize"?

Reginald-Halifrax commented 4 years ago

Of course! i said so above. it however may not be explicitly clear for other users, if that's the intended behaviour then i can accept that.

ZakBlystone commented 4 years ago

My apologies, it was late at night for me and I missed that detail. Yes this is intended behavior, it's how Garrysmod handles entities.

I've tried to think of ways to resolve this ambiguity, but doing so just adds complexity. For instance, I could have these nodes spawn with two execution pins, one for server, and one for client. But that needs to be handled for functions (hooks with return values), which creates some other downstream problems.

So far, the best solution I can think of is to have a comment over the node informing the user of this when you create a new Entity blueprint.

If you have any other suggestions, I'm open to ideas. Thanks, -Zak

Reginald-Halifrax commented 4 years ago

Best i could think of is right clicking the node to split it into its client and server pins, much like converting pure and unpure.

ZakBlystone commented 4 years ago

I'll try some experiments and see if I can make something workable.