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 /
This question was closed Nov 05, 2015 at 12:48 PM by fafase for the following reason:

The question is answered, right answer was accepted

avatar image
5
Question by Rombout · Oct 29, 2012 at 12:15 PM · c#playerprefs

PlayerPrefs does not contain a definition for 'SetInt'

Hi,

I am quite new at this but I can't seem to set an int to the playerprefs. I am using C#. The script uses MonoBehaviour.

In a OnTriggerEnter function i use the following. I've tried the official unity manual examples but I keep getting the same error. PlayerPrefs does not contain a definition for 'SetInt'. Why doesn't it recognize the SetInt (or SetFloat and so on for that matter).

PlayerPrefs.SetInt("crates", 10);

Thanks a bunch!

Comment
Comments Locked · Show 2
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 hoffmanuel · Oct 29, 2012 at 12:23 PM 0
Share

can you provide more code please? e.g. the full function

avatar image aldonaletto · Oct 29, 2012 at 01:12 PM 0
Share

Are you defining the UnityEngine namespace like below?

using UnityEngine; using System.Collections;

public class example : $$anonymous$$onoBehaviour { void Example() { PlayerPrefs.SetInt("Player Score", 10); } } If it's ok, maybe you have declared some variable called PlayerPrefs, which could hide the original PlayerPrefs class.

2 Replies

  • Sort: 
avatar image
4
Best Answer

Answer by Rombout · Oct 29, 2012 at 01:22 PM

The problem was that the scriptname and thus the class name was PlayerPrefs. I think a face palm is in order. It was driving me crazy with not even a single Google hit on the literal Unity error. Thanks again, you guys rock!

Solution for the Noobs: rename you own class to PlayerPrefsX (and keep on learning)

p.s. Can, and should, I somewhere put this question to "solved"?

Comment
Comments Locked · 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 hoffmanuel · Oct 29, 2012 at 01:24 PM 0
Share

sorry dude, but thats hillarious ^^ but for that there is this forum :)

avatar image hoffmanuel · Oct 29, 2012 at 01:34 PM 0
Share

i don't know how to mark as solved, but it seems, that the solved questions are marked as [Closed] before the question itself.

avatar image TooManySugar · Nov 05, 2015 at 11:41 AM 0
Share

Another noob here that made the same mistake. The funny part is that it worked once in other script so I moved my set string stuff to a new script named playerprefs and all screwed. loool

avatar image
2

Answer by Paulius-Liekis · Oct 29, 2012 at 01:01 PM

Maybe you removed "using UnityEngine;" from the top the the file? or defined class PlayerPrefs in your own source?

Comment
Comments Locked · Show 2 · 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 hoffmanuel · Oct 29, 2012 at 01:02 PM 0
Share

I guess, that would have already marked $$anonymous$$onoBehaviour as error. But it's possible.

Defining an own class PlayerPrefs could be the error, but would one not be able to differentiate it by the namespace?

avatar image Paulius-Liekis · Oct 29, 2012 at 01:18 PM 0
Share

Yes, I think you should be able to access Unity one by UnityEngine.PlayerPrefs

Follow this Question

Answers Answers and Comments

13 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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Differences between mobile save/load data 1 Answer

How to save different values with same script? 1 Answer

Having trouble with PlayerPrefs in my script. 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