Skip to main content
Share Your Experience: Take the 2024 Developer Survey
3 votes
Accepted

Is there a way to globally/uniquely reference a node in another scene?

Autoload I believe the Autoload approach is correct. In particular if you need to persist the state of the doors, or the door you are opening might not be loaded yet (which - if I understand correctly ...
Theraot's user avatar
  • 27k
3 votes

Is Pushdown Automata better for user input than Hierarchical State Machine?

Pushdown automata and hierarchical state machines, at least in the context of game design, are both extensions of finite state machines. Neither contradicts the other, and so you can freely use both. ...
Garrett Gutierrez's user avatar
3 votes
Accepted

Problem understanding finite state machine

Add a method public IEnemyState CreatePlayerReactState() to the Enemy class. For one enemy, have it return a DefenseState, for ...
Philipp's user avatar
  • 120k
2 votes
Accepted

Should I use single state or multiple state of an entity in finite state machine?

The character should have a single state machine. Animations should be controlled by the character state so they don't need their own character-specific state machine except as part of a generic ...
Stephane Hockenhull's user avatar
2 votes

StateMachineBehaviour.OnStateExit is called before StateMachineBehaviour.OnStateEntered is called

In case you have a transition, one state can start and the other can still be executing (updating): So yes, they can happen in the "wrong" way.
darkgaze's user avatar
  • 121
2 votes

How can I simplify my state machine transitions?

This is rather tricky question. The problem here are not flags bool can_be_jumped_from per se, but what actually lies behind it - FSM state transition. Number of ...
wondra's user avatar
  • 4,930
2 votes
Accepted

How to manage instances of (placed) cards and decks in card games?

There is never one "right" or "wrong" way to do something in programming. Just ways which do or do not work for you, your team and your project. So don't worry about doing things the right way, worry ...
Philipp's user avatar
  • 120k
2 votes
Accepted

When/where should a game state transition take place?

I generally try to have a single location where the state can change: from the update() method of the state. This allows to see quickly where one state can go from ...
Vaillancourt's user avatar
  • 16.3k
2 votes

Structure GameObject - States - Visual representation

This is usually handled in a data-driven fashion. By treating your visuals as data objects, you end up with less code micro-managing which visual to use, and you open the possibility of being able to ...
DMGregory's user avatar
  • 135k
2 votes
Accepted

Unity: Is type casting every frame too expensive?

What other's have said is correct. It likely won't cause issue. This is partially a problem with oop in general. The non casting solutions are not easy to maintain and work with. An alternative ...
gjh33's user avatar
  • 681
2 votes
Accepted

Implementing a more reliable upwards slash?

Usually the way we handle this is to introduce a new move that's a "slash precursor" whose short ~2-frame animation reads plausibly as the lead-in for either a horizontal or vertical slash. When the ...
DMGregory's user avatar
  • 135k
2 votes
Accepted

Is writing an if statement for every element in an array the most efficient way to do so?

When you compare the same variable against multiple values, then you can do that with a switch/case statement: ...
Philipp's user avatar
  • 120k
2 votes

Unity Save System - is there a better way?

Unity does not have a build-in system for saving and loading gamestates, so there is no standard solution for this. Which means that there are as many approaches to gamestate serialization as there ...
Philipp's user avatar
  • 120k
1 vote

Manage game states of a card game with MVC

From what I've understood, you want to use the States pattern to convey/control the overall game flow of the card game. You have defined 3 logical game states, Pick a card(s1), Invoke Monster(s2), and ...
Sarthak_ssg5's user avatar
1 vote

How to Prevent Enemy Overlap

In my game, I use a couple of techniques, and they are fairly simple and quick to implement. Each round, as I loop through my list of enemies. I have them register with a collision manager which ...
ErnieDingo's user avatar
  • 1,150
1 vote

Networked game with physics and client side prediction and server reconsiliation causes lag

Keep track of unconfirmed inputs (basically an array of the actual state of player's control buttons in each frame) on the client. Upon receiving the game state from the server, put the player back ...
Fanick's user avatar
  • 121
1 vote

Combining a pure ECS with a FSM scheduling system

Flat update loop The multi-phase design may be the root of the problem, because it creates a dependency graph of its own, misaligned to ECS's dependency graph. The most direct solution would be to ...
Shadows In Rain's user avatar
1 vote
Accepted

Animator State does not switch immediately through code, even tho all transitions have "Has Exit Time" checked off

As @DMGregory pointed out, the Issue was that Transition Duration of 0.25 seconds which forced the state to hold until a quarter of a second passes. Making the Transition duration zero solved the ...
Venay's user avatar
  • 207
1 vote

Using a state pattern across multiple controllers / general architecture advice

If anyone comes across this, I think I kind of figured it out. It's an architectural problem. When the game would change state, say entering into a battle cutscene, there's no reason for the ...
Robert Lee's user avatar
1 vote

Unity: Is type casting every frame too expensive?

If you can avoid casting frequently casting then do. However if you do not find it causes a reasonable performance hit then don't worry. Also it is not possible to cast GameObject to Player as you ...
rob5300's user avatar
  • 61
1 vote

Using State Pattern with Unity

It depends on the complexity of your character. Enumerations are fine for simpler characters, but it can become very problematic when character's abilities get expanded. Virtouso's answer is good, ...
Tiernan Watson's user avatar
1 vote

Using State Pattern with Unity

for working with state pattern, first thing that comes to mind is enum and state. most problem is switch is not OO and most of the time its better to not to use switch-case. and you dont have much ...
virtouso's user avatar
  • 2,628
1 vote
Accepted

If online games use permalinks

There are generally two ways to refer through the URL to a specific state The state itself is stored in the URL. The State will be serialized and then encoded to a string of valid URL-Characters. ...
tkausl's user avatar
  • 1,860
1 vote

How to represent a modular FSM for AI using ECS?

I recommend you the chapter on State-Driven Agent Design in Programming AI by Example, By Matt Buckland, since a general approach of Finite State Machines is shown there. It proposes a singleton ...
LifGwaethrakindo's user avatar
1 vote

D3D11 SetShader States

You can not bind resources to a particular shader, but a shader stage instead. For example, you bind a texture to pixel shader stage, then switch to an other pixel shader, the same texture will be ...
János Turánszki's user avatar
1 vote

Managing Discrete Character Animation States

Since you asked to expand on my first part, here it is. Currently, under states you save all your states, regardless of the relation between them, but we can ...
Giora Guttsait's user avatar
1 vote
Accepted

What component should hold the character movements in ecs and fsm?

I would suggest creating a new class just for holding the data if you are sure that the data belongs to multiple classes. Otherwise you can face tight coupling issues.
starikcetin's user avatar
  • 5,275
1 vote
Accepted

How to handle global Data within a state machine setup? (C#)

Yes, setting a global variable and then calling a method which behaves differently based on its value is a dangerous anti-pattern known as "Accumulate and Fire". The remedy is to pass all data which ...
Philipp's user avatar
  • 120k
1 vote
Accepted

InvalidOperationException when peeking from a stack within custom editor

Peek throws an exception if the Stack is empty, so you will need to check wherever appropriate that Count > 0 beforehand, or use try/catch if that matches your intent better.
jzx's user avatar
  • 3,805
1 vote

How to make a PROPER main menu (or any other UI windows/modals) in Unity?

To address your problems: With default UnityEvent you cannot pass multiple parameters in the inspector. There are plugins that allow you to do that. You are ...
Candid Moon _Max_'s user avatar

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