Hot answers tagged

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: ...
user avatar
  • 72.7k
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): <...
user avatar
  • 4,870
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 ...
user avatar
  • 111k
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: ...
user avatar
  • 112k
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 ...
user avatar
  • 2,545
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: ...
user avatar
  • 2,104
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 ...
user avatar
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: ...
user avatar
  • 13.3k
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 ...
user avatar
  • 112k
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. ...
user avatar
  • 17.9k
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 ...
user avatar
  • 462
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 ...
user avatar
  • 111k
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 ...
user avatar
  • 14.5k
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 ...
user avatar
  • 1,351
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: ...
user avatar
  • 3,395
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 ...
user avatar
  • 171
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 ...
user avatar
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 ...
user avatar
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. ...
user avatar
  • 1,987
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 ...
user avatar
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 ...
user avatar
  • 111k
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 ...
user avatar
  • 1,354
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. ...
user avatar
  • 46
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 ...
user avatar
  • 72.7k
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 ...
user avatar
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 ...
user avatar
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 ...
user avatar
  • 5,179

Only top scored, non community-wiki answers of a minimum length are eligible