Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 lorddanger · Jun 20, 2017 at 09:52 PM · buildassetsscriptableobject

how to use Scriptable Objects outside editor

Hello, I have recently started using Scriptable Objects its worked fine while in editor

But doesn't work when I build the client I have researched a bit and found that it something has to do with Resource folder but still entirely sure how to do it?

Comment
Add comment · Show 12
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 FlaSh-G · Jun 20, 2017 at 10:49 PM 0
Share

It shouldn't be necessary to involve the Resources folder, althouth there are, of course, situations where it comes in handy. But if you have problems using your ScriptableObjects in a build, it's not because you didn't use the Resources folder. Ins$$anonymous$$d, how are your SOs linked into your scene?

avatar image lorddanger · Jun 21, 2017 at 08:10 AM 0
Share

By referring the SO through the editor

public invclassSO inv;

And then dragging it on the inspector

avatar image FlaSh-G lorddanger · Jun 21, 2017 at 08:38 AM 0
Share

That should absolutely work. I'd recommend building a $$anonymous$$imal example of your problem. A simple SO that holds one string and a $$anonymous$$onoBehaviour that assigns this string to a UI text component. If this works, try to find out where the difference to your non-working code is. If it doesn't, post your $$anonymous$$imal code here.

avatar image hexagonius · Jun 21, 2017 at 10:23 AM 0
Share

Could you be more precise on what exactly doesn't work, but works in editor?

avatar image lorddanger · Jun 21, 2017 at 10:55 AM 0
Share

This is the screenshot of the inspector alt text

Code

 public $$anonymous$$apsData $$anonymous$$aps;

Error Line

 string name =   $$anonymous$$aps.$$anonymous$$apDataList[0].name;
   

This work perfectly when run inside editor but when in Build it throws error

NullReferenceException: Object reference not set to an instance of an object at G:\Unity\Projects\Demov54\Assets\Scripts\$$anonymous$$aps\$$anonymous$$ap$$anonymous$$anager.cs:105

mapmanager.png (26.2 kB)
avatar image FlaSh-G lorddanger · Jun 21, 2017 at 11:14 AM 0
Share

Is it possible that your ScriptableObject is - directly or indirectly - in a folder called "Editor"? This would cause the SO to be ignored in the build.

avatar image lorddanger · Jun 21, 2017 at 11:19 AM 0
Share

No SO is not in Editor folder

Show more comments

2 Replies

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

Answer by NoseKills · Jun 22, 2017 at 06:35 AM

I think @Bunny83 lead us to the right track. According to your screenshot you have a scene file dragged into that MapDataObj field. Scene files are editor only assets that don't get packed into builds as such. The scene fields will become null in builds

With an editor script you could probably do so that you keep the scene object reference in the editor but have the editor also track changes in it & store the name of it as a string for use in builds (or just use a manually typed string but then they'll go offsync if you rename scenes)

If this is the case, this also works as a reminder that when you post questions about errors you get, it would make everything much faster if you posted the error (which contains the line number) and the code in such format that the line numbers match with the error. Reading 150 lines of code is a lot to ask when you could do with reading just 1 :)

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 lorddanger · Jun 22, 2017 at 06:53 AM 1
Share

Problem was that exactly cause I was using Scene Data to be stored on the SO

avatar image
0

Answer by lorddanger · Jun 21, 2017 at 12:52 PM

Here is the code

 [RequireComponent(typeof(NPCSpwaner))]
 [RequireComponent(typeof(UnityClient))]
 public class MapManager : MonoBehaviour
 {
     [SerializeField]
     public int MapID;
 
     [SerializeField]
     [HideInInspector]
     private Collider TownArea;
 
 
     [SerializeField]
     private Collider HuntingArea;
 
     [SerializeField]
     private UnityClient client;
 
     public Collider GetTownArea
     {
         get { return TownArea; }
         protected set { TownArea = value; }
     }
     public Collider GetHuntingArea
     {
         get { return HuntingArea; }
         set { HuntingArea = value; }
     }
 
 
     // public Collider HuntingArea { get; protected set; }
     #region Varibles
     public MapsData Maps;
     [HideInInspector]
     public MapHelper _mapHelper;
     NPCSpwaner ns;
     #endregion
     private void Awake()
     {
         _mapHelper = new MapHelper();
         client = GetComponent<UnityClient>();
         ns = GetComponent<NPCSpwaner>();
         SetMapData();
 
 
     }
     void SetMapData()
     {
         Map _map = GetMap();
         MapID = _map.id;
         ns.MixedMap = _map.MixedMap;
         ns.isTownOnly = _map.isTownOnly;
         ns.isHuntingOnly = _map.isHuntingOnly;
         ns.isOnlyInsideHuntingArea = _map.isOnlyInsideHuntingArea;
         GetAreas();
         if (GetTownArea != null)
         {
             ns.TownArea = GetTownArea;
         }
         if (GetHuntingArea != null)
         {
             ns.HuntingArea = GetHuntingArea;
         }
     }
 
 
     void GetAreas()
     {
         GameObject areaObj = GameObject.FindGameObjectWithTag("Area");
         AreaInfo AreaInfo = areaObj.GetComponent<AreaInfo>();
         if (AreaInfo.TownArea)
         {
             GetTownArea = AreaInfo.TownArea;
         }
         if (AreaInfo.HuntArea)
         {
             GetHuntingArea = AreaInfo.HuntArea;
         }
     }
 
     Map GetMap()
     {
         Map mp = null;
         string name = SceneManager.GetActiveScene().name;
         bool checkmap = Maps.MapDataList[0]; // Edited
         int id = -1;
         if (checkmap)
         {
             mp = Maps.MapDataList[0]; // Edited
             id = mp.id;
 
         }
 
 
         return mp;
     }
 
 
     void SetMaptypes(GameObject ta, GameObject ha)
     {
         ns.MixedMap = false;
         ns.isTownOnly = false;
         ns.isHuntingOnly = false;
 
         if (ta != null && ha != null)
         {
             ns.MixedMap = true;
         }
         else if (ha == null)
         {
             ns.isTownOnly = true;
         }
         else if (ta == null)
         {
             ns.isHuntingOnly = true;
         }
     }
 
 
     public void MapDataFromServer(object sender, MessageReceivedEventArgs e)
     {
         _mapHelper.ReceivedMapData(sender, e);
         ns.Spwaner(_mapHelper.Map);
     }
 
     public void CreatTheWriterForSpwanList(List<int> FailedSpwanUids)
     {
         DarkRiftWriter writer = new DarkRiftWriter();
         writer.Write(MapID);
         if (FailedSpwanUids.Count > 0)
         {
             foreach (int u in FailedSpwanUids)
             {
                 writer.Write(u);
             }
             SendDataToServer(Tags.MapManager, Tags.MapManagerSubjects.FailedNPCSpwan, writer);
         }
     }
 
     void SendDataToServer(byte tags, ushort Subject, DarkRiftWriter writer)
     {
         //Send Failed Position to srever
         Debug.Log("Sent The failed position to the server");
         TagSubjectMessage message = new TagSubjectMessage(tags, Subject, writer);
         client.SendMessage(message, SendMode.Unreliable);
     }
 }
 
Comment
Add comment · Show 3 · 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 Bunny83 · Jun 22, 2017 at 01:46 AM 0
Share

A few points:

  • First of all you posted an answer to your question but you don't answer anything in your post. If you want to improve your question, you should edit the question.

  • Second the line you mentioned in your comment above doesn't seem to exist in your actual code. Either you have changed your code or something else is not right.

  • Finally the line which might be closest to the offending line (line 85 in your code here) is a bit strange.

This is the line 85 of your code:

 bool checkmap = $$anonymous$$aps.$$anonymous$$apDataList.Exists(x => x.$$anonymous$$apDataObj.name == name);

What exactly is stored / referenced in that $$anonymous$$apDataObj variable of your $$anonymous$$ap object? Why do you use the variable type UntiyEngine.Object ? Are you sure that every $$anonymous$$ap object in your List has a valid object assigned to it's $$anonymous$$apDataObj variable?

avatar image lorddanger Bunny83 · Jun 22, 2017 at 06:50 AM 0
Share

First of all you posted an answer to your question but you don't answer anything in your post. If you want to improve your question, you should edit the question. Ans :: At the time of posting the code I was outside and did that with my Phone and I was not able edit my initial question

Second the line you mentioned in your comment above doesn't seem to exist in your actual code. Either you have changed your code or something else is not right. Ans :: Yes that code was from the main project not from the test script which I was using to for fixing it

Finally the line which might be closest to the offending line (line 85 in your code here) is a bit strange.

And the final the problem is mainly then after build the $$anonymous$$aps which holds the SO become null

avatar image NoseKills lorddanger · Jun 22, 2017 at 06:55 AM 0
Share

You should be able to edit questions on your phone too by pressing the gear button -> edit , or post a comment ins$$anonymous$$d. Under answers and questions there's a Add comment button. When commenting on a comment on mobile you have to tap the comment to bring up the Reply -option

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

73 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

Related Questions

Distribute terrain in zones 3 Answers

Is it possible to change builds structures? 2 Answers

Scriptable Objects not appearing on Build 0 Answers

How To Refresh Resources Folder in Build? 1 Answer

Building for Mod Compatability 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