Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 /
  • Help Room /
avatar image
0
Question by Firestream1014 · Apr 05 at 05:56 AM · scriptableobjectcrashingscriptable object

Changing ScriptableObject to another during runtime crashes UnityEditor

I found that that this was not the issue however I still do not have a fix. When killing enemies, the editor freezes. My new post.

I have an inventory system that uses scriptableobjects for the items(ItemObject), I have an enemy that on death instantiates a 'lootbag' prefab with the item script on it which references one of the scriptableobject ItemObjects. On my enemy script I have a List<> containing possible ItemObject drops to set that 'lootbag's ItemObject to. Sometimes when they die it functions fine, other times it permanently freezes the editor/makes it go unresponsive. Enemy's Line:

 reward_object.GetComponent<Item>().SetItem(rewards[Random.Range(0, rewards.Count - 1)]);

Item's Line:

 public void SetItem(ItemObject _itemObject)
     {
         item = _itemObject;
     }

If I need to provide more of the script please let me know. Using Unity version 2020.3.3f1

Comment
Add comment · Show 5
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 Hellium · Apr 05 at 07:05 AM 1
Share

Anything in the logs?

rewards[Random.Range(0, rewards.Count + 1)] should be rewards[Random.Range(0, rewards.Count)] by the way. Random.Range excludes the provided upper bound but if Random.Range returns rewards.Count, you'll have an IndexOutOfRangeException

avatar image Firestream1014 Hellium · Apr 05 at 07:30 AM 0
Share

As in console logs or should I try and find a crash log somewhere? If console logs than no there's no error it just instantlly freezes after instantiating the lootbag. Perhaps that's the issue, I was reading into random.range and found that the upper number was excluded so I thought I'd need to increase it. Thank you!

avatar image Firestream1014 Hellium · Apr 05 at 07:46 AM 0
Share

Well, I guess I wasn't thinking through it very well initially since the List's index starts at 0 so I ended up changing this rewards[Random.Range(0, rewards.Count + 1)]; to rewards[Random.Range(0, rewards.Count - 1)]; but sadly the issue remains, sometimes the item will drop correctly but sometimes it'll make the editor go unresponsive permanently.

avatar image Hellium Firestream1014 · Apr 05 at 06:56 PM 1
Share

You need rewards[Random.Range(0, rewards.Count)], not rewards[Random.Range(0, rewards.Count - 1)]


But anyway, I really doubt this is the cause of your issue. A hanging editor usually comes from an infinite loop.

Show more comments

0 Replies

· Add your reply
  • Sort: 

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

184 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 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

Scriptable Objects and Assetbundles 0 Answers

ScriptableObject Referencing 1 Answer

Why can't I set an Animation reference in a Scriptable Object instance? 1 Answer

Scripts vs ScriptableObject 1 Answer

ScriptableObject Life Cycle [ Help ] 0 Answers


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