Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 critterawesome · Jun 03, 2021 at 09:30 PM · unity 5dotsstatic variablereadonly

How to use SharedStatic? ECS Burst SystemBase

So i recently posted a question about accessing and writing to static readonly variables and it has led me to shared static. Does anyone here know how to initialize a shared static variable such as this.

 public static NativeMultiHashMap<int, QuadrantData> quadrantMultiHashMap = new NativeMultiHashMap<int, QuadrantData>(0, Allocator.Persistent);

but in shared static.

Manual: https://docs.unity3d.com/Packages/com.unity.burst@1.2/manual/index.html?_ga=2.116916166.1198962832.1621981940-1822029584.1618698935&_gl=1*17xq55r*_ga*MTgyMjAyOTU4NC4xNjE4Njk4OTM1*_ga_1S78EFL1W5*MTYyMjc1Mjk2OC40OC4xLjE2MjI3NTUyMTguNjA.#shared-static

to be clear the only reason i need this is to write to static readonly variable.

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

2 Replies

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

Answer by andrew-lukasik · Jun 03, 2021 at 11:30 PM

I know what that error message said... but it was misleading in this case. You don't need SharedStatic to fix BC1042 as this is NativeMultiHashMap and you're not synchronizing pointers to different NativeMultiHashMaps across managed-unmanaged memory domains, aren't you?

To the contrary - you have a singleton of type NativeMultiHashMap and just trying to access it's data in different points of your code, which in turn triggers this ambiguous compiler error.

To fix this BC1042 here, you need to stop accessing static fields inside burst-compiled code blocks, that's it.

Comment
Add comment · Show 5 · 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 andrew-lukasik · Jun 04, 2021 at 10:32 AM 0
Share

What's more, this doesn't has to be a static field at all. If you remove this static keyword, it will remain accessible from other systems (given dependencies are resolved) as long as it's a public field:

 var quadrantSystem = World.GetExistingSystem<QuadrantSystem>();
 var quadrants = quadrantSystem.quadrantMultiHashMap;
avatar image critterawesome andrew-lukasik · Jun 04, 2021 at 02:13 PM 0
Share

I will try your solution out it seems to be a sensible answer.

avatar image critterawesome andrew-lukasik · Jun 04, 2021 at 02:28 PM 0
Share

we are getting close but another error has popped up insisting that error DC0004: Entities.ForEach Lambda expression captures a non-value type 'quadrantSystem'. This is only allowed with .WithoutBurst() and .Run()

avatar image andrew-lukasik critterawesome · Jun 04, 2021 at 05:55 PM 0
Share

Yes, it is to be expected. Don't reference systems (a class) in a job. Reference structs there only (native hash map is one)

Show more comments
avatar image
1

Answer by critterawesome · Jun 04, 2021 at 08:58 PM

Thanks andrew lukasik! i implemented your suggestion after a long time of errors and debugging and it finally works!

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

211 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 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

SystemBase ECS unity doesnt let me acess NativeMultiHashMap because it isnt readonly? 2 Answers

why my static timer variable print 0 everytime i call the getcolor function?! 0 Answers

Acessing static variable from Entities.ForEach 1 Answer

Will DOTS Netcode be easier than Photon? 2 Answers

Understanding transform.LookAt() 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