Skip to main content
13 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 ...
Philipp's user avatar
  • 121k
11 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 ...
Ian Young's user avatar
  • 2,669
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: ...
DMGregory's user avatar
  • 135k
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 ...
DMGregory's user avatar
  • 135k
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. ...
Theraot's user avatar
  • 27.3k
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 ...
Victor T.'s user avatar
  • 1,381
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: ...
Kevin's user avatar
  • 6,494
4 votes
Accepted

When detecting a keyboard key is released. What happened if the key is released at the end of the game loop?

The System events will be placed in SFML's event queue and be processed during the next loop. Imagine if the events were lost? What a bad game dev library that would make! Roughly, the way a program ...
Vaillancourt's user avatar
  • 16.3k
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 ...
Breakthrough's user avatar
3 votes

How can you subscribe to Unity input events, instead of polling for them

If you want an event-based input handling in modern Unity, then you might want to use the new input system. While it can be used in a polling manner like the classic Input system, it is designed to be ...
Philipp's user avatar
  • 121k
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. ...
Fang0r's user avatar
  • 44
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 ...
House's user avatar
  • 73.3k
3 votes

Game loop on windows

No, you are not wrong. Actually that's true - if there are too many events the else will never be run, or at least will not be run quickly enough. If your UI methods take too much time to process the ...
Marcin Skoczylas's user avatar
3 votes

Event handling in Pure Entity Component Systems, is this approach correct?

Your question boils down to Is it a good idea to use a publisher-subscriber-based GUI and to keep this subsystem distinct from my ECS (while enabling interop between them)? Yes, keep your UI and ...
Engineer's user avatar
  • 30.1k
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 ...
TheBeardyMan's 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 ...
Kasper van den Berg's user avatar
3 votes
Accepted

Efficient way to detect when audio clip ends

isPlaying will also return false if the song gets paused via. Pause. Therefore I'd recommend waiting for the ...
IndieGameDev's 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 ...
Ed Marty's user avatar
  • 5,229
3 votes

OnMouse Events stop working when multiple cameras are active

I found a workaround for those interested. Before setting your overlay camera to overlay, head to rendering - priority, and set to a number lower than your main camera. After that, you may change ...
mikeohc's user avatar
  • 31
3 votes
Accepted

How to call a function in response to a Button's OnSelect event?

Edit: I added the OnSelect version. Note that selecting and highlighting / hovering are two different things. When you hover over your button with mouse, OnPointerEnter will be triggered (if using ...
ezez's user avatar
  • 326
3 votes
Accepted

How to see which mouse button was pressed (Unity Input System)

You don't. The InputActions assets in the new input system are meant to create an abstraction layer between different pieces of input hardware and what actions ...
Philipp's user avatar
  • 121k
3 votes
Accepted

Is it necessary to unsubscribe from C# events when the event owner has already been destroyed?

Expanding on the answer I gave here, we can test this by using a script that holds references to both a publisher and subscriber "gently" and then checks whether they've been successfully ...
DMGregory's user avatar
  • 135k
3 votes

How to get the name of a function added as a listener to a Button's onClick event?

I felt fancy and decided to answer the actual question. You can do that with some reflection: ...
starikcetin's user avatar
  • 5,305
3 votes

Area2D only detecting body_exited once

The ball being an static body is odd... I suspect the Area2D is not detecting the static body at all, see the issue: Area2D does not detect moving StaticBody2D. I ...
Theraot's user avatar
  • 27.3k
2 votes

Is it efficient to only store interface pointers for components in an entity-component system?

I'd say that if you do indeed want anything that implements EventListener to be eligible for inclusion as a part of GameObject (or Game), then sure, that's a good way to go. However, that also means ...
Rakurai's user avatar
  • 156
2 votes
Accepted

How to know which methods are associated with an event?

You want to get the InvocationList of the event. Here is a brief code example : ...
Uri Popov's user avatar
  • 3,027
2 votes

How to prevent sending semantically wrong messages in event based architecture?

In a comment you said that every message is only valid for one scope. When that's the case, you actually have three separate message systems here and should have separated infrastructures for them. ...
Philipp's user avatar
  • 121k

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