• 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
Question by Selene · Sep 14, 2011 at 03:14 PM · playerprefsx

SetString error with PlayerPrefsX

Hello,

I am using the ArrayPrefs2 script from wiki (PlayerPrefsX.js). When I'm trying to save some strings in an array I get the following error.

"NullReferenceException: Object reference not set to an instance of an object PlayerPrefsX.SetStringArray (System.String key, System.String[] stringArray) (at Assets/Standard Assets/Scripts/PlayerPrefsX.js:175)"

Here's the line what I'm using:

 PlayerPrefsX.SetStringArray ("Diary_text_1", diary.story_text);

  • story_text is a string array (`var story_text = new String[21];`) where I want to store some strings and what I want to save.

Does anyone has any idea what could be the problem here? Thanks in advance.

Comment

People who like this

0 Show 0
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

Answer by Eric5h5 · Sep 14, 2011 at 04:15 PM

diary.story_text is probably wrong; see here for accessing other game objects.

Comment

People who like this

0 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 Selene · Sep 15, 2011 at 07:43 AM 0
Share

story_text is a global variable in my diary.js script and I didn't have any problems accessing it like this in my other scripts.

avatar image Selene · Sep 15, 2011 at 08:54 AM 0
Share

In the error message it shows that it might be a problem at the 175th line in the PlayerPrefsX script. In that line of the script is this: if (stringArray[i].Length > 255) I don't know how could this be the problem, since the strings that I am trying to save none of them is longer than 40. Or is it that the whole array cannot be longer than 255?

avatar image Eric5h5 · Sep 15, 2011 at 01:33 PM 0
Share

stringArray[i].Length is the length of the string for entry i. stringArray.Length would be the length of the array. In that case I would guess you're trying to save null entries in the array.

avatar image

Answer by Selene · Sep 15, 2011 at 02:32 PM

I managed to solve the problem. The problem was indeed with the story_text variable, although the issue wasn't that it couldn't be accessed. (I was assigning some other variables to that and was trying to save those and not the actual array.)

Now I have another question. Can you tell me how can I check if a string key already exists? I would need t$$anonymous$$s so if it exists only then I will load it. Thanks.

Comment

People who like this

0 Show 0 · 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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How to save rotation with PlayerPrefsX? 1 Answer

Attempting to store an Inventory Array in PlayerPrefsX 1 Answer

PlayerPrefsX.SetBoolArray not saving 1 Answer

PlayerPrefsX Question 1 Answer

Using PlayerPrefs to save a C# Generic List 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