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
1
Question by ThugsInMugs · Jun 23, 2020 at 11:00 PM · scriptableobjectcustom editor

Why does my scriptable object asset lose items in a list after first playthrough?

Hello everyone! Long time no see in these forums. Im currently using UnityEngine 2019.3.9f1


So essentially I wanted to create a super versatile dialog system (with textmesh pro). I made an editor window and everything. It essentially works like a nintendo game from the early 2000s - it feeds text through the UI by individual dialog boxes (or one instance of blurb before waiting for the input for next chat box). But it also feeds by individual words too, meaning you can apply effects to words that are important, slow down the type speed of individual words to show a character is thinking, or make font bigger to show a character is angry. This tool also triggers events when the dialog is closed. I do intend on making this tool public and free use when I feel its full :)


Heres the thing, its done and functional (even has some effects). I can create a "dialog asset" just fine. Then I can plug it in perfectly the first playthrough, but heres the problem, when I close out of the first test, all the child objects inside the dialog asset are missing (I'll explain how it works later). Before I do the first playthrough however, the list of "snipets" when opened are labeled as "type mismatch"


All the dialog assets are made up of is three parts: The Dialog, the snipets, and the lines. All three have their own respective public scriptable object classes.


When you open the editor window it creates a new instance of dialog. All that is inside Dialog is a public list of Snipets. When you press the large button that says create new snippet, using the CreateInstance(typeof(Snipet)) function, it adds a snippet to the list of snippets. Inside of snippets, theres some floats and bools but the main thing is a list of type line. When you press the Create new line, it does the same thing as before with the snipets.


When you press save dialog, I use AssetDatabase.CreateAsset and it makes everything just fine. I can even press the "type mismatch" and it opens the given snipet in the inspector. This is my first time really working with scriptable objects and making my own tool, is there something else Im supposed to be doing? Like I said before everything works the first playthrough but after Im done, it wipes the dialog asset's snipet children. Id supply screenshots but I keep getting an error right now.

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

1 Reply

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

Answer by Bunny83 · Jun 24, 2020 at 01:49 AM

Did you actually save any of your child objects? So all those snippets and line objects? ScriptableObjects are standalone assets. They either have to be stored in a seperate .asset file or you could pack multiple objects into the same asset file by using AssetDatabase.AddObjectToAsset.


References to scriptable objects are actual serialized references. Just adding scriptable objects into a serialized list won't save all those objects. When you create a ScriptableObject with CreateInstance it only exist in memory / in the current scene. If you want such an object to persist you have to use CreateAsset or AddObjectToAsset.

Comment
Add comment · Show 1 · 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 ThugsInMugs · Jun 24, 2020 at 02:35 AM 0
Share

Thank you very much! I had no idea about AddObjectToAsset! Would I have to add each line after I create the initial asset? (I can simply loop through them, I just need to know when I should do AddObject to Asset). Very helpful information though, I just started getting into all the obscure serialize stuff.

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

134 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

Related Questions

Object field not working in custom editor for scriptable object? 0 Answers

[Custom Editor] MonoBehaviour vs Scriptable Object 0 Answers

"Unbroken Reference" problem when using a custom Editor to Save/Load a ScriptableObject Asset 0 Answers

Creating a Scriptable Object Custom Editor Footer 0 Answers

ScriptableObject Custom Asset Error on Build and First Starting Unity 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