Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by jesse-small · Mar 11, 2021 at 07:20 PM · multiplayer-networkingscriptable object

How to create a searchable list of ScriptableObjects?

I am currently working on a multiplayer network game and the problem I am looking to solve is the following. My game contains effects that can be applied to the player. I have a created a "BaseEffect" scriptable object that is used to create different effects with all of the values/logic contained to be applied to a player. I would like to avoid passing the entire effect object over the network when being applied to another player, instead I would like to pass EffectId = 0 so the server/client can simply look up the effect via its ID and apply it to the player.

What would be the best way of doing this, while keeping them as scriptable objects?

Should I create a static list of these scriptable objects that is accessible at runtime for reference? Or is there a cleaner way to have a searchable list of scriptable objects.


Also: Is my idea of passing over the effectID vs the entire effect object a bad idea? if so why?


Example:

 PlayerA uses "Slow" on PlayerB 
 PlayerA send request to server to apply effect with ID = 2 to PlayerB
 Server verifies request, tells PlayerB client to apply effect with ID = 2 to itself
 PlayerB looks up effect with ID = 2 and applies the slow effect.

Thanks for any advice!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by GetLitGames · Mar 11, 2021 at 09:46 PM

  1. Add an Id property, whether an int or string

  2. use the Unity Singleton pattern on a class like public class ItemDefinition: Singleton, and attach it to a gameobject in your scene like ItemManager https://wiki.unity3d.com/index.php/Singleton

  3. add an array[] or List Items of your scriptableobject class as a [serializedfield] (ItemDefinition is a scriptableobject in this example)

  4. drag all your scriptables from your project into your array/list on the gameobject inspector and save the scene

  5. add a public method like ItemDefinition GetItemById(int id)

  6. ItemDefinition GetItemById(int id) { return Items.FirstOrDefault(x => x.Id == id); }

  7. anywhere you need it just use ItemManager.Instance.GetItemById(1); and it will return the ItemDefinition scriptable or a null if the id isn't found

  8. assign the return to a variable, and use the variable multiple times - don't just paste GetItemById everywhere

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by jesse-small · Mar 18, 2021 at 04:56 PM

I accepted @SubtleTechnology answer as it ended up being very similar to my implementation. I ended up creating a pseudo "database" object that accepted a list of scriptable objects and had a custom editor button to initialize all of its IDs for me. This ensured I could give each SO a unique ID and had an easy way to reset the IDs if needed. (My logic does not depend on IDs staying the same between sessions, and this is very handy for debugging purposes).

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

119 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Networking question 2 Answers

How to control other Clients in multiplayer 1 Answer

Can I see how many bytes are being sent by a particular SyncVar variable? 1 Answer

Problems with Scene Change networking Unet 0 Answers

How to set namespace in packet of socketIO using unity3d 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges