This site uses cookies! Learn More

This site uses cookies!

armedunity.com uses cookies to improve user experience.

By continuing to use this site, you agree to allow us to store cookies on your computer.

YoungDeveloper

Basic Idea of Creating any Item list in Game

14 posts in this topic

After this thread Please login or register to see this link. i understand'ed why pretty much

i have not seen any project here with large item data structures. Mostly couple pickable objects which are found using tag or name.

 

Before writing an actual code, i would like talk about couple things, like what is overall basic idea from game creation perspective itself.

Map designers, quest creators and many others, these people mostly never code when creating maps, quests, place npc etc. They have ready custom built tools for doing that, all what they do is move sliders, search through lists and place/write (not code).

 

So, before actually creating the game experience itself, we need to make sure that we the right tools for doing that process, it will be taking a long time to create the map, so each helpful thing for the map designers can save tens of hours.

 

One way would be storing ready prefabs in one folder, but imagine if prefab amount is around 4 thousand, considering all little props, items, mobs etc. Artist will drive nuts working like that. So, custom editors is the only option, you could sort specific item lists under different categories, also show how they look or will look. That would be much more easier to work with and focus on map building than trying to find specific item for 10 minutes.

 

It means, each item, Quest, NPC, monster, gun, attachment, etc should be somehow recognizable (specific number or something), but how? If in simple case all what it has is a tag ?

 

Creating a structured list for each type of item would be best logic, for example one list for pistols, one for magazines etc. When the list is created you can easily access it from any point in your game And custom editors. Which means if you update you food list, your custom editor will automatically will be updated.

So basically when having these lists, you can spawn anything and anywhere  And track things via Log.

 

So first, we create the list (array) which will hold information about the items. This script should be on player itself.

Please login or register to see this code.

After attaching script you basically now can create item list in any size you want, and each can contain lots of information.

 

Now we need a script which will be located on item itself, so we would know what item is that.

Please login or register to see this code.

Yes, that's it :).

 

 

Now the script which will find the item.
Also on player.

Please login or register to see this code.
  • Set the list in size of 1 (in inspector), in first element fields, enter its name and weight.
  • Place ThisItem script on the pickable item, set index to 0, tag should be "Item"

 

After triggering the item the text will appear and it will be destroyed.

 

This is the basic idea how you can create very advanced item in game structures.

Sorry if i didn't notice grammar errors, and i didn't test the code, as i am writing this from phone.
If you have any problems or questions, ask.

12 people like this

Share this post


Link to post
Share on other sites

You are welcome, a bit of lecture there, but i hope it was somewhat interesting hehe

1 person likes this

Share this post


Link to post
Share on other sites

well documented and simple to understand looks effective from my perspective i like it good job  :-BD

Share this post


Link to post
Share on other sites

@YoungDeveloper Nice explanation for people who don not know much about classes. One thing is I don't think you can use name as a variable name. I believe you have to capitalize it "Name" because of a unity predefined name. I could be wrong tho.

@Everyone when dealing with array classes, make sure you use a name variable as shown, if not, it can get very confusing because labled as an element. By adding a name variable, it will change the name of the element in the inspector to your own specifications. Even if you won't be using it for anything else

1 person likes this

Share this post


Link to post
Share on other sites

You can use name as a variable name, if couldn't i wouldn't use variable name with a capital N anyway, as it would be a bit of out of proportion (talking about code etiquette). And classes is pretty much the only option, as structs are not Serializable ans pointers are not allowed.

 

I'd prefer to use struct if i could.

Share this post


Link to post
Share on other sites

Could be pretty messy if you have a lot of ingame items, which is why I usually just parse through an XML database for stuff like this.

Share this post


Link to post
Share on other sites

You can't pass something that player doesn't know what that is, player would still need to have that information.

You could use that for instantiating objects, not actually sending the object itself.

1 person likes this

Share this post


Link to post
Share on other sites

Sorry for the noob question but what if I need the item to be instantiated as a prefab. Same item but should have different index right? Can this be done through code too?

Share this post


Link to post
Share on other sites
Please login or register to see this quote.

 

You add GameObject variable in Item class and drag it in inspector.

Share this post


Link to post
Share on other sites

I think the items class you created should be using a singleton method. Would make it a lot easier to call upon the functions in that class or access the class in general. An example here:Please login or register to see this link.

Creating singleton "managers" allows for persistent data between scenes without having to always rely on playerprefs function. Just an idea. I currently use this method with success on a few published games.

Share this post


Link to post
Share on other sites
Please login or register to see this quote.

 

I dont think you understand purpose why i posted this, it's a "Basic Idea of Creating any Item list in Game", which is not dynamic.

Purpose of this is exact opposite of singleton method.

 

Instead of trying to bugger old topics which are mainly meant for complete beginners you could post an example in free scripts.

;)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now