Entity Name and .ToString()

Post and discuss features you'd like to see in the BEPUphysics library.
Post Reply
-=Magic=-
Posts: 41
Joined: Thu Jun 30, 2011 11:32 am

Entity Name and .ToString()

Post by -=Magic=- »

I think that it will be usefull if we may assign a Name to an entity, and overriding the default .ToString method so that the Name sill be returned.
In this way, build a log file to debug the physic should me more easy.

I've added to the EntityBase class this code:

Code: Select all

        public string Name { get; set; }

        public override string ToString()
        {
            if (String.IsNullOrEmpty(Name))
                return base.ToString();
            return Name;
        }
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Entity Name and .ToString()

Post by Norbo »

I would recommend using the Tag property for this purpose; it was designed to hold arbitrary user data.

I will modify the ToString method to return the Tag's ToString as well if it is not null.
-=Magic=-
Posts: 41
Joined: Thu Jun 30, 2011 11:32 am

Re: Entity Name and .ToString()

Post by -=Magic=- »

but the Tag could be used to store other kind of infos... the Name is just for "debug" purposes. if I need to use Tag for this, and I need to use the Tag for other purposes.. then I have to complicate the whole thing, passing an object array as Tag.. so you choice still useless, beacuse ToString will return object array.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Entity Name and .ToString()

Post by Norbo »

I try to avoid 'extra' features in the API since things can get cluttered. The Tag is capable of serving the same purpose as the Name, and Name can't do much else besides act like a crippled Tag.

If the Tag needs to contain a Name as well as other gameplay data, the recommended approach is to make a class which contains all the user data and stick that object into the Tag. An array can work too, but it's usually less direct.
Post Reply