Tag Info

New answers tagged

1

Usually you will have your game engine alongside a rendering engine. The System which contains the Render Components will not do the drawing. It will ensure each Render Component is properly synchronised with the current animation, position etc... Concerning the rendering it will happen outside of your system in the render engine as you ...


0

I'm currently using the Visitor Pattern ( Wikipedia link) as the basis of my rendering system for my game. Basically, I have several interfaces defined to support this: (Note, this is basically an abstract recreation of part of my games system, and most likely does not reflect current code) interface ISystem { void Accept(EntityBase entity); void ...


2

This kind of defeats one of the main purposes of having components in the first place. What I think you actually want is something like this: class SpriteSystem { void SpriteSystem::Draw() { foreach(var sprite in sprites) { this.DrawSprite(sprite); } } } class Sprite { public Sprite::Sprite() { ...


3

I'll try to explain with an example: Let's say we have an RPG where you can enchant your weapons with elemental damage. The weapon still have a "physical" attack power, which is reduced by the enemies "phyical armor". But now we have elemental damage, and thus the enemies might have elemental resistances. This is perfect for Entity Component System, ...


8

Applying the RequireComponent decoration to a script will ensure that the GameObject has the specified component. If the component is missing: Unity will attempt to add a component of this type for you, If this fails (e.g. mixing RigidBody/RigidBody2D) then the script will refuse to attach. C# sample: [RequireComponent (typeof (Rigidbody))] public ...


3

Unity has built in functionality for this called RequireComponent. Used like this in Unityscript: @script RequireComponent(Terrain) This will actually automatically add a Terrain component to the object if it doesn't have one already. If the user removes the Terrain component, your script will throw a compile error about the missing component.


1

Two methods come to mind, but none are very elegant. 1) Implement OnValidate(). The downside is that's it's called only when modifying component's values, or entering/exiting game mode. void OnValidate() { if (GetComponent<Terrain>() == null) { Debug.LogError("You can't attach this component without terrain!"); ...



Top 50 recent answers are included