i am gettign this error, even though i am not even using multithreading or anything like that, which when i was reading others’ solutions seemed to be that the others were.
here is where it happens:
[System.Serializable]
public struct SaveSystemItemSlot{
public string itemPath;
public Int64 count;
public SaveSystemItemSlot(Item item, Int64 am ount){
itemPath = item.name; //HERE
count = amount;
}
}
so the problem here is itemPath = item.name;
also, it worked before, i didn’t change really anything related to this. (if that helps in any way) anyways, thanks.
Unitys API isn’t thread safe. As a general rule don’t call into it on anything other than the main thread.
Also just pass the itemPath / name string into the constructor if thats all you want.
Im assuming Item
is a class that inherits from monobehavior, which means it has game object and transform properties.
item.name (lower case n) refers to the name of the game object in the scene view. This property is locked on the Unity thread only, which means it can’t be accessed by another thread.
Instead, create a new property called item.Name (upper case n), which is a string, and is thread-accessible. Set that to item.name in the Unity thread, and when you’re in the other thread, access item.Name instead.