Tag Info

New answers tagged

1

Applying the RequireComponent decoration to a script will ensure that the GameObject has the specified component. If the component is missing: Unity will atempt 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 class ...


0

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.


0

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!"); ...


0

Unity's Entity-Component-System implementation isn't an ideal model on which to base a custom ECS. Unity favors ease of use over strict adherence to the ECS paradigm and made lots of trade-offs to serve that end. Where Unity falls short of a pure ECS is the lack of separation between data and logic. In a pure ECS components contain only data and the logic ...


0

To expand on crancran's answer, I will share our experiences with the ECS we use at work. Each component has the ability to be registered with a list of that component type. For example, our ModelComponent is registered with a ComponentList in it's create function, and removed in it's destroy function. Each frame, in the update loop, different systems are ...


2

While components may have logic in them, the sort of logic you're talking about (loosely termed batch logic) doesn't exist at the entity level -- instead it exists in the game loop. This makes sense when you look at a theoretical (but typical) deferred 3D renderer. This renderer may have to run through all objects of similar type (a data member of your ...


1

There is no one right answer. I open with that because I know there are many who disagree with what I'm about to say. I do use NewtonSoft for JSON serializing and deserializing, but from a somewhat different angle. After much experience with apis and file formats, I've settled on the approach of designing the file format (or network message format, in some ...


2

After a few hours of work I found I could create a custom converter by extending JsonConverter. I used this answer to help me out. I got my output to look like: "components": [ { "name": "position", "x": 50, "y": 20 }, { "name": "health", "HP": 100 } ] I added my converter as an attribute to the ...


0

There are often lots of items in a game that can be used in varying ways. One generic way to do this is to implement an interface such as the following: class IUsable { public: virtual void Use() { /* does nothing */ } } For items which are usable on the current player such as potions, their Use method send an event to the current player with the ...


0

In my implementation I have a ITransform interface. The transform is implemented either with a standalone Transform (implementing the ITransform) or when using 2D physics with the Box2DComponent (which also implements the ITransform). This way I can chose to directly use physics or not depending on each entity's purpose and both types can coexist in the ...


0

Here is another thought, Although I'm not sure how good it will perform: The thing is, the Transform component is mandatory, but it doesn't really matter the internal class is, as long as it provides position, rotation and other details about an object's spacial properties. What I mean is, you can have to classes, both providing all the information ...



Top 50 recent answers are included