Skip to main content
9 votes
Accepted

Does interfacing not work as well when it comes to games development?

Unity emphasizes a philosophy called Composition Over Inheritance. The idea is that rather than thinking of what a particular entity "is": A soldier is a unit which is selectable and which is ...
DMGregory's user avatar
  • 135k
5 votes
Accepted

Does abstraction influence performance?

It looks like you don't really need to ask "Does abstraction influence performance?" - because you did one better: you tested and measured it! "The problem I am facing with version 2 is that the game ...
DMGregory's user avatar
  • 135k
4 votes
Accepted

How do I switch between different Update behaviour states in Unity?

If you just want different behaviours for different states, but without complicated switching logic in your Update loop, I'd recommend using Coroutines. That way you keep the related behaviour in one ...
DMGregory's user avatar
  • 135k
3 votes
Accepted

What is the best practice for creating a system of platforms that does not use Unity's tag system?

Depending on the level of complexity required you could go one of two routes: If you have a set of GameObjects that represent the different block types and all you need are a set of properties to ...
Zhaph - Ben Duguid's user avatar
2 votes

C# What is the advantage of using interfaces for simulating multiple inheritance?

An interface represents a contract, they're used to allow a method to state that it needs something that fulfills that contract, when the actual details of that contract aren't known. You example is ...
bornander's user avatar
  • 4,516
2 votes
Accepted

how to make weapon charge up behavior using composition

Something like the input handler using Command pattern should work. The goal is to isolate weapons and their basic operations like fire(), ...
congusbongus's user avatar
  • 14.8k
2 votes

Polymorphism vs cache-friendliness

I wouldn't do that, as you'd complicate things unnecessarily. Keep a single generic list of entities and compact toward the beginning of the array every so often. That way you will get far fewer cache ...
Engineer's user avatar
  • 30k
2 votes

Making unity inspector accept classes that inherit from a base class

I'm unable to reproduce the problem described in this question when using types that are derived from MonoBehaviour or ...
DMGregory's user avatar
  • 135k
2 votes

Unitys [SerializeField] and parallel inheritance

It looks to me like you might actually want an IItem interface, or abstract class, a bit like this: ...
DMGregory's user avatar
  • 135k
2 votes
Accepted

Instantiating, Inheritance, Objects and Children basics in Unity

if I make a c# script "BlueEnemyScript" inherit from script "EnemyScript", that's a "child object" in c#? No, when you define something like ...
DMGregory's user avatar
  • 135k
2 votes
Accepted

Destroyed GameObject but still trying to access it(C# Unity)

I'll answer my own question . What i did here is that this line of code ...
NoobProgrammer's user avatar
2 votes

RPG Item Design

Similar to the answer to the question referenced by Philipp, you might consider using a general system of events and flags for every item: CanEquip, OnEquip/OnDeEquip CanConsume, OnConsume ...
jzx's user avatar
  • 3,805
2 votes

How do I switch between different Update behaviour states in Unity?

Simply put, you simply override the base methods. The problem I see is not that you can not call the specific Update; it is that you can not call ...
Gnemlock's user avatar
  • 5,273
2 votes
Accepted

Why can't this event call its parent event?

Answered my own question within minutes of asking. How I created this problem When overriding parent events in Unreal, you must right click and use the context menu to add the event you want to ...
Natalo77's user avatar
  • 689
2 votes
Accepted

How to inherit from a custom node of a gdnative plugin, in gdnative?

At some level we could argue for Godot being data oriented (e.g. the code inside the "servers", such as VisualServer and so on), or we can argue that the ...
Theraot's user avatar
  • 27.2k
1 vote
Accepted

C++: Setup the basic Update function in different classes which all derive from GameObject

You'd want to use polymorphism. In your case : ...
mukuro's user avatar
  • 26
1 vote

Use GKEntity's component(ofType:) with inheritance

Well it appears as if no one here seems to know it so I'll just post what I used which is a new method that I added in an extension to GKEntity (which I was ...
lsauceda's user avatar
  • 151
1 vote

C++ inheriting functions problem

Java is object oriented, that is, it makes heavy use of inheritance, but the syntax is a little different. In C++ we declare a base class, which can be viewed as an interface, thusly: ...
Ian Young's user avatar
  • 2,649
1 vote
Accepted

C++ inheriting functions problem

In the future, make sure to write the error the compiler gives. In c++, for a function to work, you need (generally) two things: a declaration, and a definition. (In some situations, both can be ...
Vaillancourt's user avatar
  • 16.3k
1 vote
Accepted

why child class can access object while parent can't

Since I used a start method too in the child class I should have written it that way override protected void Start() { //some code base.Start(); } and in ...
Abeer's user avatar
  • 25
1 vote

XNA: Classes with Texture2D to be treated as one

You can either just extend Texture2D, which would allow you to cast it down to a Texture2D if you want or (in my opinion preferably) extend the spriteBatch with a draw that accepts Animations. To be ...
Bálint's user avatar
  • 14.9k
1 vote
Accepted

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

In Unity, I'd generally recommend working with the principle of composition over inheritance. In this case, if player characters, enemies, and environment objects all need to take damage, then damage-...
DMGregory's user avatar
  • 135k
1 vote
Accepted

Java: Updating entities in composite design

why don't you make lists of your interface? ...
Martin Frank's user avatar
1 vote

How to expose a child node’s texture from the parent in Godot

Let us start with your code: ...
Theraot's user avatar
  • 27.2k
1 vote
Accepted

How to expose a child node’s texture from the parent in Godot

I would export the texture variable from the root node and simply set the child texture in _ready(), rather than mess around with getters and setters. ...
DyingIsFun's user avatar
  • 1,307
1 vote
Accepted

How to use base.Function() in Unity

As indicated by the compiler, the function can't be private. In C#, the default visibility is private. When you want to create virtual functions which can be ...
Hellium's user avatar
  • 2,949

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