Questions tagged [polymorphism]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0 votes
2 answers
123 views

How to replace if/else/switch with polymorphisim

For a long time Robert Martin has been advising against if/else/switch branching logic and instead rely on the polymorphic behavior of different types. ...
user avatar
  • 5,986
0 votes
1 answer
28 views

Problem with Parameters for polymorphism class

This is going to be a bit tricky but it is really bothering me so I hope you will have the patience to follow along :) Here is my very basic architecture: So in the framework, I am creating I have <...
user avatar
0 votes
0 answers
83 views

is there any different solution for different buildings different behaviours

I'm trying to make different behaviours for workers of different buildings, let's say an agricultural worker would need to sow wheat seed and collect the wheat grain when it's grown. let's call that <...
user avatar
0 votes
0 answers
73 views

Remove nested if statements

I have been learning a new method of programming. I have been programming many years and am recently finding out there is a better method in general via abstract classes. My question is how to ...
user avatar
0 votes
1 answer
55 views

Interact with inheriting class methods from "casted" base class (collisions, etc)

I want to implement a damage system that works across both living items (Entity) and environment items (Environment). The key ...
user avatar
  • 107
1 vote
1 answer
1k views

RPG Item Design [duplicate]

I'm currently fiddling around with some RPG mechanics and I'm trying to implement a solid way to handle items that have different on use effects. Currently, I have a base class called "Item" that ...
user avatar
3 votes
2 answers
838 views

Using polymorphism in an Entity-Component System without sacrificing data-oriented design

I've been planning out an Entity-Component System in C++. My idea of it is most in line with the one described on this page of the entity systems wiki. To summarize, components are just structs of ...
user avatar
0 votes
2 answers
191 views

How to: Duplicating and updating component data in systems

I am new to game development. Coming across the ECS (entity-component system) pattern I generally quite liked the idea. I have implemented the current version of my engine using the OOP style approach....
user avatar
0 votes
1 answer
579 views

Make the components of an ECS polymorphic

I have implemented an entity component sytsem (ECS) in my game engine (SFML and C++ 17). An entity has an array of components. You can get a components by its type e.g.: ...
user avatar
1 vote
1 answer
404 views

Component based Entity System using polymorphism: OpenGL does not render

I want to be able to create Entities from different Component sets. I want to call Entity entity(new StaticObject(modelpath, position)); I have an EntityTypes ...
user avatar
  • 145
2 votes
2 answers
219 views

Cost of Using Virtual Methods to Query Properties?

Let's say you're making a tile-based roll-playing game, and you're obsessed with OOP. You have an abstract base class Tile which will be inherited from by many ...
user avatar
  • 1,018
1 vote
1 answer
243 views

Inherited property in derived class reference only base class

[Context] I am developing a game in Unity, and wanted to make a Game Manager. Like many examples out there, it uses a Singletron design pattern. But i have several other Managers, all using Singletron ...
user avatar
3 votes
1 answer
1k views

'Ball.rigidbody' hides inherited member 'Component.Rigidbody'

I have some understanding of c# and I am new to unity. I am currently making a 3D project which use the Rigidbody component on the ball object. When I use following code: ...
user avatar
  • 133
2 votes
1 answer
2k views

Unity polymorphism in editor through a list

So I have an ItemDatabase class which basically only has a list of Item ...
user avatar
  • 173
6 votes
1 answer
5k views

Unity3D [C#]: How do I use a custom inspector to expose an array of polymorphic objects to edit?

[EDIT: based on some feedback, I pruned the example down to the base functionality of the bug we are trying to solve. The description below remains accurate, but the repro has been shortened to: Add ...
user avatar
3 votes
1 answer
1k views

Collision Shapes Abstraction Design

Straight to the facts. I have a base CEntity class for different entities in my game: Static entities ( those do not move, simply props and items ) Dynamic entities ( these move, jump ) Each of ...
user avatar
  • 55
0 votes
1 answer
120 views

Interface or Class Inheritance [closed]

I am making an inventory system. Different inventory item will have different uses so i am thinking about making a base class called InventoryItem and derive Wood, Gold, Weapons and so on. This way ...
user avatar
  • 809
9 votes
3 answers
1k views

Flexible alternatives to many many small polymorphic classes (for use as properties or messages or events) C++

There are two classes in my game that are really useful, but slowly becoming a pain. Message and Property (property is essentially a component). They both derive from a base class and contain a ...
user avatar
  • 235
5 votes
4 answers
2k views

Inheritance Hierarchy and Design -- avoiding multiple inheritance

I am working on a 3D game, and need some advice about how to best design and structure my code so that I achieve what I'm going for without using bad practices like multiple inheritance. Basically ...
user avatar
  • 239
1 vote
1 answer
2k views

Creating an abstract Animation class

I'm creating a simple 2d game with c++ and SFML, and I've got a simple framework going for animating a sprite using a "SpriteSheet" image (an big image containing all the "frames" of an animation) I'...
user avatar
  • 13
0 votes
1 answer
584 views

Problem creating levels using inherited classes/polymorphism

I'm trying to write my level classes by having a base class that each level class inherits from...The base class uses pure virtual functions. My base class is only going to be used as a vector that'...
user avatar
  • 77
2 votes
2 answers
135 views

How to handle similar actions in derived actors (inheritance)

I have a base class called Attacker that has a update method. The update method moves ...
user avatar
  • 476
-7 votes
2 answers
770 views

Component-based entities without IDs?

I'd like to know if someone has found a way to build a component-based entity system in their game(s) without using IDs. I find that IDs tend to do away with one of the major (possible) advantages of ...
user avatar
  • 3,167