43
votes
Accepted
How do I ensure a piece of code runs only once?
Use a boolean flag.
In the example shown, you'd modify the code to be something like the following:
...
22
votes
How do I ensure a piece of code runs only once?
Should bool flag not suffice or you wanted to improve readability* of the code in void Update() method, you could consider using delegates (function pointers):
<...
11
votes
Accepted
How to correctly implement custom tick system?
The second solution will perform slightly less ticks than expected over time, because when tickTimer is slightly larger than ...
10
votes
Accepted
How to make a custom event system framerate friendly?
This looks like you could solve it with a priority queue or min-heap. The code to process the queue would look something like this:
...
8
votes
Accepted
Event handling in Pure Entity Component Systems, is this approach correct?
Merging systems, such as collision and collision response, is a bad idea. The reason being that there can be many different responses to collisions: Physics based, and game-logic based.
In most game ...
6
votes
Accepted
How can you subscribe to Unity input events, instead of polling for them
There's no built-in way to do that. If you prefer an event based solution you can wrap all input polling inside a component and expose the relative and subscribe for them.
Some like:
...
5
votes
Event-driven Communication in a Game Engine: Yes or No?
Yes. It is a very efficient way for game systems to communicate with each other. Events help you decouple many systems and make it possible to even compile things separately without knowing of each ...
5
votes
Accepted
Good techniques for syncing gameplay actions to specific animation timings?
For synchronisation, you need to decide who (your code, animations, or neither) is the timing authority—the "beat" that everyone else "dances" to.
Different arrangements suit different games:
...
5
votes
Accepted
Centralized event system using dictionary
This looks like a situation you can tackle with the curiously recurring template pattern.
First, we'll define a generic GameEvent, that could work on payloads of some unknown type, with static ...
5
votes
Accepted
Is it better to connect signals in source code or with the IDE feature?
Abstract
Should the connection be persisted? No: Connect from code.
Should the connection happen on load? No: Connect from code.
Should the connection be removed on runtime? Yes: Connect from code.
...
4
votes
Accepted
EventManager adding data to the event message
I often see people over-engineering event systems, my advice would be to keep it simple.
For a simple game an enum suffices to identify events. For games with a large amount of events from different ...
4
votes
Turning a board game idea into a browser based, slow paced gameplay
Instead of completely refilling all players action points at a fixed time, you could instead give them a small amount of action points every few minutes and allow them to safe up action points up to ...
4
votes
Accepted
How to design parameters for events
Don't shove all the events into one type. You are using C++, a language that supports Abstract Data Types. Use them!
Inheritance/Interfaces
...
4
votes
Accepted
Event Trigger for sprite not working
I see that the backward image is turned around 180 degrees to make it face opposite the direction of the forward image. This means that its front side is facing away from the camera. By default, this ...
4
votes
Accepted
How could I intercept a save scene action being run in Unity?
Unity already has a built-in event for doing exactly what you want: EditorSceneManager.sceneSaving
Usage:
...
3
votes
Accepted
Event-/Input system with SFML: Cannot move diagonally in 2D
I would personally use the keyboard class that allows you to query the state of keys instead of waiting for an event.
The documentation is here
One of the reasons I prefer this method is that you ...
3
votes
Accepted
How do I trigger OnSelect() via the ISelectHandler in my class?
I managed to figure this out. You need to manually tell the EventSystem that the object has been selected. On a method such as ...
3
votes
Turning a board game idea into a browser based, slow paced gameplay
You might want to look at internet Diplomacy, which takes the simultaneous moves approach. Diplomacy assumes you will be discussing moves with other players, so you have some idea of what is going ...
3
votes
Accepted
Event Handling in an ECS
The DieOnCollision event couples behavior to an event. This causes tight coupling and could be why you're having trouble deciding how to handle these use cases. ...
3
votes
Accepted
Multi-threading for rhythm game?
TL,DR: The SDL2 event/render system is not yet thread-safe, but you can overcome this limitation by using OpenGL to decouple the renderer system from your application (and then perform all rendering ...
3
votes
Accepted
How to implement specific custom events in an Event Condition Action (ECA) game system?
The event "A unit owned by player 12 dies" implies the "A unit dies" event. So there is no reason to have two different events.
You should only need a single "Unit death" event, but have that event ...
3
votes
How do I ensure a piece of code runs only once?
For completeness
(Not actually recommending that you do this as it's actually pretty straightforward to just write something like if(!already_called), but it would ...
3
votes
How to stop diagonally in an event driven input system?
If you want this kind of interaction, you'll have to introduce some sort of delay into your controls because it is very unlikely that the player will be able to release both keys in the same frame. ...
3
votes
Accepted
C# Script file is not showing in Onclick Event in Unity 5.0.4f1?
You need to add the LevelLoader script to the LevelLoader object in the hierarchy panel. Then drag the entire LevelLoader object (not script) from the hierarchy ...
3
votes
Accepted
How do I make a quest requiring a certain number of a specific item?
A Conditional Branch cannot refer directly to the quantity of an item, but the quantity can be copied to a variable, and the Conditional Branch can refer directly to that.
Before your Conditional ...
3
votes
Accepted
Effect Replacement System
Split the actions, such as "main weapon melee attack" in the OP's example into smaller actions and conditions. Recombine them using a behaviour tree. For example:
Normally the purpose of a ...
3
votes
Accepted
Can Event Triggers be used on Non-UI objects?
You can do this if you add a Physics Raycaster component to your camera. Just make sure you have colliders on the same GameObjects that have the EventTriggers you want to be clickable.
You also have ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
events × 249unity × 70
c# × 42
architecture × 40
input × 28
c++ × 22
java × 17
keyboard × 13
xna × 11
libgdx × 11
javascript × 10
game-loop × 10
timer × 10
gui × 8
entity-system × 8
game-design × 7
animation × 6
performance × 6
actionscript-3 × 6
design-patterns × 6
frame-rate × 6
2d × 5
xna-4.0 × 5
software-engineering × 5
sdl × 5