How to best handle ScriptableObjects in a multiplayer game
So I am using classes which derive from ScriptableObject to store stats for weapons ("Weapon") and attachments ("Attachment"). For example, the prefab, the damage, the fire rate etc. are all stored in my class "Weapon". I originally thought using these would be as easy as putting a "Weapon" variable on a "Inventory" script placed on the player gameobject. On start, the ScriptableObject would be accessed, the prefab in there instantiated and the player "knows" how much damage the weapon is supposed to do and so on. However, I ran into the problem that when I try to "externally" modify the inventory (the server changes which gun the player has) I can not use a ScriptableObject reference as Unet can't use prefabs and the likes, only gameobjects actually existing in the scene. Therefore, as a workaround, I now use a string which is the path to the ScriptableObject, send said string over the network and the Client then uses Resource.Load to get the corresponding ScriptableObject. Question is, is this the intended use of ScriptableObjects in networking? Is there a better way of storing Item stats than ScriptableObjects for multiplayer?
Any response appreciated and feel free for clarification if anything I described is unclear.
Answer by BruceKristelijn · Dec 10, 2018 at 04:22 PM
I personally think you way of storing and referencing the scriptable object is good enough but you can also look into filling a dictionary with all scriptableobjects and assigning a name to them (Maybe just the name of the SO).
In the editor you can fill a list with all scriptableobjects and when you start you can convert this list to a dictionary with a function like this:
Dictionary dict = new Dictionary ();
void Convert(){
foreach(var obj in objects){
dict.add(obj.name, obj);
}
}
This is just y idea though so look into it, and make sure to tell me what works best :)
Your answer
Follow this Question
Related Questions
Scriptable Objects are secure in multiplayer? 1 Answer
How do I make a item system with ScriptableObjects where different items can have durability? 1 Answer
uNet, doubt Pickup and drop objects 0 Answers
How to create a multiple players project in my account (Unity Plus license) 0 Answers
Making different users see their data on the same canvas 0 Answers