简体   繁体   English

从ScriptableObject类中删除属性/字段

[英]Removing a property / field from ScriptableObject class

I posted this to Unity Answers as well but haven't gotten any hits, so I thought I'd try here too. 我也将其发布到Unity Answers,但没有获得任何成功,所以我想我也可以在这里尝试。

So I'm doing some refactoring on my Unity game that uses a ScriptableObject to contain a weapon definition. 因此,我正在使用ScriptableObject包含武器定义的Unity游戏中进行一些重构。 I'm wanting to remove one of the public properties in the weapon definition as it is no longer needed. 我要删除武器定义中的一个公共属性,因为不再需要它。 Here's my class in full, I'm wanting to get rid of shotParticlesPrefab : 这是我的全部课程,我想摆脱shotParticlesPrefab

public class WeaponDefinition : ScriptableObject
{
    public const int DefaultWeaponDamage = 50;
    public const float DefaultWeaponFireRate = 0.25f;
    public const float DefaultWeaponShotSpeed = 600;

    public ActorWeaponShot shotPrefab;

    public ParticleSystem shotParticlesPrefab;

    public AudioClip shotAudio;

    public int damage = DefaultWeaponDamage;

    public float fireRate = DefaultWeaponFireRate;

    public float shotSpeed = DefaultWeaponShotSpeed;
}

However, when I try to remove the property from the ScriptableObject, Unity gives me the following error: 但是,当我尝试从ScriptableObject中删除属性时,Unity给我以下错误:

Assets/Scripts/Actors/ActorWeapon.cs(64,53): error CS1061: Type 'WeaponDefinition' does not contain a definition for 'shotParticlesPrefab' and no extension method 'shotParticlesPrefab' of type `WeaponDefinition' could be found. 资产/脚本/演员/ActorWeapon.cs(64,53):错误CS1061:类型“ WeaponDefinition”不包含“ shotParticlesPrefab”的定义,并且找不到类型为“ WeaponDefinition”的扩展方法“ shotParticlesPrefab”。 Are you missing an assembly reference? 您是否缺少装配参考?

I tried restarting Unity and Visual Studio, but after the restart none of my scripts on any of my prefabs would load because of the error. 我尝试重新启动Unity和Visual Studio,但是重新启动后,由于该错误,我的任何预制板上的所有脚本均无法加载。 I also tried cleaning up references in the existing weapon definitions (basically setting shotParticlesPrefab to None) but had no joy there either. 我还尝试清理现有武器定义中的引用(基本上将shotParticlesPrefab设置为“无”),但那里也不高兴。 After restoring the property, all returned to normal without issues but leaves me with a property I don't need anymore. 恢复该属性后,所有属性均恢复正常,但是我却拥有不再需要的属性。

What's the proper way to go about this? 解决这个问题的正确方法是什么? Is it possible to remove a property on a ScriptableObject after instances of it have been created in a project? 在项目中创建ScriptableObject的实例后,是否可以删除该属性? Do I have to delete all existing instances of the ScriptableObject before changes are possible? 在进行更改之前,是否必须删除ScriptableObject的所有现有实例? That would be a rather ugly solution, so I haven't tried that yet. 那将是一个相当丑陋的解决方案,所以我还没有尝试过。 :| :|

My best Google-Fu attempts didn't yield any results on something like this issue, so here I am. 我最大的Google-Fu尝试在类似此问题上没有产生任何结果,所以我在这里。 :) Any thoughts would be greatly appreciated. :)任何想法将不胜感激。 Thanks. 谢谢。

ActorWeapon正在尝试使用现在不存在的属性,请打开ActorWeapon并删除引用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM