Hot answers tagged

67 votes
Accepted

Should I avoid using object inheritance as possible to develop a game?

Favour composition over inheritance in your entity and inventory/item systems. This advice tends to apply to game logic structures, when the way in which you can assemble complex things (at runtime) ...
  • 29.3k
20 votes

Should I avoid using object inheritance as possible to develop a game?

You got a few nice answers already, but the huge elephant in the room in your question is this one: heard from someone that using inheritance must be avoided, and we should use interfaces instead ...
  • 485
14 votes

Should I avoid using object inheritance as possible to develop a game?

The idea that inheritance must be avoided is simply wrong. There exists a coding principle called Composition over Inheritance. It says that you can achieve the same things with composition, and it's ...
  • 536
8 votes
Accepted

Unity Hybrid ECS with "old way"

It is perfectly possible to mix both styles. The same GameObject can have some of its functionality implemented with the new ECS system and other functionality in classic MonoBehaviour events. What ...
  • 114k
6 votes
Accepted

How should entities in a game reference each other?

As you've noticed, there are pros and cons to each architecture scheme. Each pattern has its own implications for how objects will interact, and when. First, I'd recommend a quick refresher on SOLID ...
  • 3,785
6 votes

How do I correctly use singletons in C++ engine programming?

Inherit from sf::RenderWindow SFML actually encourages you to inherit from its classes. class GameWindow: public sf::RenderWindow{}; From here, you create ...
  • 1,028
6 votes
Accepted

Designing PHP RPG game: Should I use multiple classes for each type of item or a single table?

A rule of thumb is that you use different classes when objects require different code and instances of the same class when the objects only require different values. So when ...
  • 114k
6 votes

Component oriented programming for rich RPG world

Taking the example of the guitar: (...) a player you can, for example, not only play on guitar as a Musical Instrument, but use it as a Weapon or, what is perhaps more unobvious, throw it right to ...
  • 20.4k
6 votes

Should I avoid using object inheritance as possible to develop a game?

The problem is that inheritance leads to coupling--your objects need to know more about each other. That's why the rule is "Always favor composition over inheritance". This doesn't mean NEVER use ...
  • 219
5 votes

Cost of Using Virtual Methods to Query Properties?

obsessed with OOP What you've described isn't OOP. It's an abuse of inheritance, which is frequently attributed to OOP, but isn't an inherent part of the paradigm. :) My question is, what is the ...
5 votes
Accepted

Cost of Using Virtual Methods to Query Properties?

No. Grass, Sand and Water aren't different TYPES of tiles, they are different tiles. i.e. ...
4 votes
Accepted

How should my game characters store their abilities/spells?

The idea is to have spell objects hold some reference to the in-code action you want that spell to do. Python's first-class functions make this quite nice (I'll assume Python 2.7.x): ...
  • 13.3k
4 votes
Accepted

UPDATED: Deserialise Nested JSON with JSON Utility Unity 5.4

Your JSON firstly is faulty and secondly does not match the data model. To break down your JSON: ...
3 votes
Accepted

Ideas/suggestions to implement an item combination system

When you handle all item combinations in the Inventory class, that class will potentially grow to an enormous size because it needs to implement the combination logic to handle every single item ...
  • 114k
3 votes

How do I correctly use singletons in C++ engine programming?

Singletons are not bad. Instead they are easy to abuse. On the other hand, globals are even easier to abuse and have loads more problems. The only valid reason to replace a singleton with a global is ...
  • 9,947
3 votes

How do I correctly use singletons in C++ engine programming?

You avoid singletons in game development the same way you avoid them in every other kind of software development: you pass the dependencies. With that out of the way, you can choose to pass the ...
  • 218
3 votes

Good design for skills (heal,dmg etc)

I think you are looking in what's called the "Strategy pattern" in OOP. Your skill has something like the following signature(in pseudocode) ...
  • 965
3 votes
Accepted

How do I correctly use singletons in C++ engine programming?

Only store data needed to render the sprite inside each entity, then retrieve it from the entity and pass it to the window for rendering. No need to store any window or view data inside entities. ...
3 votes

How should entities in a game reference each other?

A slight variant to jzx's implementation would be to use an update method similar to how you did your draw. It's not uncommon in architectural design to have some context object that often holds a ...
  • 2,012
3 votes

Class design and data structures for a Tower Defense

Instead of having a TowerType enum and a lot of if/else/...
  • 114k
3 votes
Accepted

OOP design principles that fit with Unity

Unity does cater for that sort of abstraction, however you have to do some additional work to leverage it. In my current project I have series of characters that can be controlled by the player or by ...
  • 214
3 votes
Accepted

Three levels deep composition (player<-character<-spell), with preset character+skill sets

This looks like a job for the Flyweight Pattern! (Closely related to the Type Object pattern) Here you separate the concept of a character archetype from the instance of the character itself. You ...
  • 122k
3 votes
Accepted

How to link my weapons with their corresponding ammo supply in the Unity Inspector?

You probably don't actually want your weapon to hold a reference to the instance representing your ammo stock of its type. That makes it very difficult to set up a weapon prefab for a pickup/powerup, ...
  • 122k
3 votes

Should I avoid using object inheritance as possible to develop a game?

Contrary to the other answers, this has nothing to do with inheritance vs. composition. Inheritance vs. composition is a decision you make regarding how a class will be implemented. Interfaces vs. ...
3 votes

Passing a value to a stuct

you are copying in your ranged-for loop. You should use for (auto& path : Path) This will pass by reference and allow you to make changes to the variable ...
  • 839
3 votes
Accepted

How to modularly call a script based on parameters within the script?

You can have just one interface, an IAction or similar. Make Lift implement it. Then, inside your main ...
  • 425

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