ml-agents
ml-agents copied to clipboard
error CS0122: 'ModelAssetData' is inaccessible due to its protection level
I already have the correct installation since it follows the steps correctly and I don't get any errors. But when I try to import the "3D ball" scene to Unity I get the following error
Assets\ML-Agents\Examples\SharedAssets\Scripts\ModelOverrider.cs(306,68): error CS0122: 'ModelAssetData' is inaccessible due to its protection level.
- Unity Version: 2023.2.0f1
- OS + version: Windows 10
- ML-Agents version: branch 21
- Torch version: 2.1.1
- Environment: 3D ball
- Python 3.10.12
I would appreciate the help, I have tried many things but I have no ideas left.
Hi, has anyone found a solution yet? I'm facing the same issue.
ModelAsset LoadSentisModel(byte[] rawModel)
{
var asset = ScriptableObject.CreateInstance<ModelAsset>();
var modelAssetDataType = typeof(ModelAsset).Assembly.GetType("NamespaceOfModelAssetData.ModelAssetData");
var modelAssetDataInstance = ScriptableObject.CreateInstance(modelAssetDataType);
FieldInfo modelAssetDataField = typeof(ModelAsset).GetField("modelAssetData", BindingFlags.NonPublic | BindingFlags.Instance);
if (modelAssetDataField != null)
{
modelAssetDataField.SetValue(asset, modelAssetDataInstance);
FieldInfo valueField = modelAssetDataType.GetField("value", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
if (valueField != null)
{
valueField.SetValue(modelAssetDataInstance, rawModel);
}
else
{
Debug.LogError("Failed to retrieve the value field from ModelAssetData.");
}
}
else
{
Debug.LogError("Failed to retrieve modelAssetData field from ModelAsset using reflection.");
}
return asset;
}
The above code works for me, Find the ModelAsset LoadSentisModel Method in the project file: project\Assets\ML-Agents\Examples\SharedAssets\Scripts\ModelOverrider.cs
also add the using System.Reflection;
After this replace the method with this code and you should get a working sample. The sample seems to work as intended. Hope this helps!
ModelAsset LoadSentisModel(byte[] rawModel) { var asset = ScriptableObject.CreateInstance<ModelAsset>(); var modelAssetDataType = typeof(ModelAsset).Assembly.GetType("NamespaceOfModelAssetData.ModelAssetData"); var modelAssetDataInstance = ScriptableObject.CreateInstance(modelAssetDataType); FieldInfo modelAssetDataField = typeof(ModelAsset).GetField("modelAssetData", BindingFlags.NonPublic | BindingFlags.Instance); if (modelAssetDataField != null) { modelAssetDataField.SetValue(asset, modelAssetDataInstance); FieldInfo valueField = modelAssetDataType.GetField("value", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); if (valueField != null) { valueField.SetValue(modelAssetDataInstance, rawModel); } else { Debug.LogError("Failed to retrieve the value field from ModelAssetData."); } } else { Debug.LogError("Failed to retrieve modelAssetData field from ModelAsset using reflection."); } return asset; }The above code works for me, Find the ModelAsset LoadSentisModel Method in the project file: project\Assets\ML-Agents\Examples\SharedAssets\Scripts\ModelOverrider.cs
also add the using System.Reflection;
After this replace the method with this code and you should get a working sample. The sample seems to work as intended. Hope this helps!
Worked for me, thanks!
Worked for me too! Thankkkkk!
J0hnnyGee , Thank you. your code worked!
Worked for me, too. Thank you!
This issue is stale because it has been open for 30 days with no activity.
Using reflection does solve the problem, but it's obviously not the normal solution, and since ModelAssetData became an internal variable with one of the sentis updates, sentis should have provided some other way of updating this variable at the same time, or else I can't figure out what the purpose of this change was
ModelAsset LoadSentisModel(byte[] rawModel) { var asset = ScriptableObject.CreateInstance<ModelAsset>(); var modelAssetDataType = typeof(ModelAsset).Assembly.GetType("NamespaceOfModelAssetData.ModelAssetData"); var modelAssetDataInstance = ScriptableObject.CreateInstance(modelAssetDataType); FieldInfo modelAssetDataField = typeof(ModelAsset).GetField("modelAssetData", BindingFlags.NonPublic | BindingFlags.Instance); if (modelAssetDataField != null) { modelAssetDataField.SetValue(asset, modelAssetDataInstance); FieldInfo valueField = modelAssetDataType.GetField("value", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); if (valueField != null) { valueField.SetValue(modelAssetDataInstance, rawModel); } else { Debug.LogError("Failed to retrieve the value field from ModelAssetData."); } } else { Debug.LogError("Failed to retrieve modelAssetData field from ModelAsset using reflection."); } return asset; }The above code works for me, Find the ModelAsset LoadSentisModel Method in the project file: project\Assets\ML-Agents\Examples\SharedAssets\Scripts\ModelOverrider.cs
also add the using System.Reflection;
After this replace the method with this code and you should get a working sample. The sample seems to work as intended. Hope this helps!
Worked for me!! Thank you so much!
Also add: using Debug = UnityEngine.Debug;
Really helpful!! Thank you
Really helpful, thanks a lot!
Thank you!!!
Worked for me! Thanks!