yueyi27
yueyi27

Reputation: 1

Question about data access control in game programming with ECS (Entity-Component-System)

We're developing a game with ECS (Entity-Component-System).

Because all data stored in components are public, so everyone can access them easily. Sometimes somebody modify the data by mistake, which cause a bug that is hard to find it.

I want to make a tool to restrict access and then a system can only access some fixed components. How can I do this?

Upvotes: 0

Views: 166

Answers (1)

Monza
Monza

Reputation: 755

I think that for Unity dev activities most of the values are usually left open and easily changeable. If you have something that needs to be public within your C# but not visible from the Unity Editor, define it as a

public var {get;set;}

If you need to further restrict within Unity, define your variable as a

public var {get; private set;}

If you really need further protection, break the values into an accessor and backing variable, ie:

var _x;
public var X
{
  get {return _x;}
  set {
      if( valueAllowedToBeWritten)
        _x = value;
      }

Good luck!

Upvotes: 0

Related Questions