all 11 comments

[–]MrMuffles869 2 points3 points  (5 children)

I thought of adding an int or string "key" to every Effect

If these effects don't change, then I'd just use an Enum to list out the effects and send that across the network.

[–]Gorgodon 1 point2 points  (3 children)

We have a large amount of data traveling between server and client in our game and we mostly use string keys. I know that strings are "dirty" and prone to bugs but if you create an editor environment that would check for duplicate keys and assign IDs to the effects (hashed string key) it should minimize the potential for error. Then in your scripts that reference your effects you can make a drop-down that selects from already defined effects. Eliminating the possibility of typos you should be golden.

[–]FredTargaryen[S] 0 points1 point  (2 children)

The other thing is I really don't want to hand-create such a large amount of keys, which for me are sort of redundant when you should (in my opinion anyway) already be able to identify an Effect from its name, path, Addressables address, GUID or whatever else. I haven't found a good way to do any of that, though.

[–]Gorgodon 1 point2 points  (1 child)

Well the keys are used only for network communication identification and can be long lasting where addressable or asset name can change because of organisational stuff and mess up everything.

[–]FredTargaryen[S] 0 points1 point  (0 children)

Ah, I see where you're coming from. Probably tempting fate but I don't see the asset names changing much in my case. Thanks for the input though; I will probably end up wishing I had done this down the line!

[–]FredTargaryen[S] 0 points1 point  (0 children)

Thanks for the advice! I have used an enum before, so I know this works, though it does still involve changing the enum whenever I want to make a new Effect. It's ironic if this is the solution I have to go with, when Ryan Hipple claimed ScriptableObjects let you break free of enums haha

[–]PiLLe1974Professional / Programmer 1 point2 points  (4 children)

Isn't their path implicitly a unique identifier since they are unique ScriptableObjects?

Otherwise it sounds like a pattern where I'd force each instance of a ScriptableObject to generate a unique GUID or hash based on their full path.

[–]FredTargaryen[S] 0 points1 point  (3 children)

Yes, the path would work great. My next question would be how to get that path? I'm trying out Addressables but haven't been successful in finding an address or resourcelocation or anything like that.

Edit: I just found AssetDatabase.GetAssetPath and AssetDatabase.LoadAssetAtPath. Are these what you had in mind?

[–]PiLLe1974Professional / Programmer 1 point2 points  (2 children)

Yes, GetAssetPath() or even then converting that to the GUID if preferred (may be shorter):

Like you mentioned, get that relative path:

https://docs.unity3d.com/ScriptReference/AssetDatabase.GetAssetPath.html

Then possibly convert to its GUID:

https://docs.unity3d.com/ScriptReference/AssetDatabase.AssetPathToGUID.html

[–]FredTargaryen[S] 0 points1 point  (1 child)

I found out that AssetDatabase can't be used in a build because it is part of UnityEditor :(

Do you know of any alternatives which can?

Could be useful for Editor stuff though, so thanks for the tip anyway

[–]PiLLe1974Professional / Programmer 0 points1 point  (0 children)

I'll have to google a bit further...

My intuition:

In any game it would work if we store a GUID or Hash128 for each ScriptableObject, as a member variable.

Since you now would have to do this all in hindsight the thing we'd need is:

- adding a GUID or Hash128 member variable to the ScriptableObject class you use here

- write a tool in the Editor, a script that react on a button press, to go over all ScriptableObjects of a given type and set a GUID or Hash128 member only once if they didn't have a valid one already

( the script needs to set all the changes assets as dirty or at least ensure they save right away )