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 krayzie_762 · May 07, 2015 at 09:04 AM · editorinspectormaskfieldbinary

Problem with MaskField ints

I am trying to script a MaskField with a dynamic list of Object names, then add/remove Object from another list depending on the int value derived from the MaskField, but maskfield seems to always give out a full "11111111111111111111111111111111" when "everything" is checked and it prints an int of -1, regardless of the amount of objects in the list. So if i have a list of two things, it will give me that for "everything" and if i uncheck 1 thing it will give me a number like "11111111111111111111111111111101" and prints as -3;

so to summarize:

MaskField has 2 listed objects. Select one and i get binary of "1" Select the other and i get binary of "10" Select "Everything" and i get binary of "11111111111111111111111111111111", int prints as -1. Deselect one and i get binary of "11111111111111111111111111111101", int prints as -3.

i tried using unsigned ints and longs and none of that works

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
0

Answer by Bunny83 · May 07, 2015 at 09:16 AM

Well, and what's the problem with that? It's a bit mask so it behaves exactly the way it should be. If you only need the last two bits just use a bitwise "and" ( & ) with 3 and you only get the last two bits. Or to test a single bit in the mask use

 if((maskValue & (1 << bitIndex)) > 0)

where "bitIndex" is an index starting at 0.

Since it's a bitmask you shouldn't treat the int value as a whole. You usually test if certain bits are set or not.

If you want to mask only the lower "n" bits you can use this:

 int lowerBits = maskValue & ((1 << bitCount)-1);

where bitCount is the count of bits you want, in your case 2.

Comment
Add comment · 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.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How to assign a field within a PropertyDrawer? 1 Answer

exclude public field from inspector 2 Answers

How to record hideFlags for Undo/Redo 0 Answers

Exposing Enums in Custom Inspector 1 Answer

How to make a serialized editor only field 2 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