#Trying to access scriptable object that inheriting from other scriptable object.

1 messages · Page 1 of 1 (latest)

ivory lionBOT
#

An image of your code is not helpful

When asking a question about a problem with code, people who are volunteering to help need the text of the code. Unless you are asking about your IDE - and not the code itself - images of the code are not an acceptable substitute.
Source: https://idownvotedbecau.se/imageofcode

Please send your code as a codeblock. If you don't know how to send a codeblock, type []cb

summer jetty
#

Inheritance only works downwards.
If you want to access the properties of a child class (WeaponScriptable) from a reference to a base class (ItemScriptable), you will need to explicitly tell your code, that you expect your base class to be an instance of the child class.
The easiest way to do this, would be to use the as keyword: cs StartCoroutine(StartAttackCooldown((ItemData as WeaponScriptable).weaponSpeed));However, this may become an issue, if ItemData is not an instance of WeaponScriptable but of some other item type. Then you'll get a NullReferenceException as the cast returns null.
A way around this, would be the is keyword: cs if (ItemData is WeaponScriptable weapon) { StartCoroutine(StartAttackCooldown(weapon.weaponSpeed)); }This would only try to access weaponSpeed, if the value of ItemData actually is a WeaponScriptable.

worthy elbow