12/31/2023 0 Comments Unity ai with scriptable objects![]() ![]() Let me know what you guys think, am I being dramatic? There's just something I don't like about having to rely on monobehaviors and import settings. The animation events can easily be lost when editing the import settings, this will cause problems 1 and 2 to repeatĪ scriptable object could have a description of the event, the key required, and the target model that it was created for. Scriptable objects are always present, the only reference that is required is to a gameobject that processes the event.Īfter some time, the designer finds out that the new animations are dense in keyframes, he begins editing the import settings on the animation. The designer hits play and is greeted with a note from one of the developers "The scriptable object (name) caught the event but was not able to execute it because a reference game object has not been set" because he forgot to apply the monobehaviour scripts ![]() The designer hits play and is greeted with a bunch of error messages, one for each event that is not caught. The designer decides to change the character model to match the new animation, The artists looks for WalkingSFX and references the key value. In the project folder we have a list of scriptable objects that are named corresponding to the event they catch. The animation event targeted a scriptable object. The events are deleted and the artist doesn't remember what was the string for the footstep animations, he has to refer to the monobehaviour script. An artist on the team is experimenting with new animations, they decide to replace the animation with a new one. I want the character to have footstep sounds. I created three Scriptable Objects for my Unity word game: FeemData - This is to hold information on letters NeemData - This is to hold information on pronunciation SuperNeemData - This is to hold 1 and 2 together in a single Scriptable Object. Here is a simple use case, I have a demo walking animation that I'm using as part of the development cycle. I posted an idea on the unity feedback page to encourage developing this feature. Switch ( Unity doesn't support targeting a scriptable object as the receiver for animation events. public enum ElementType Īnd DoDamage() can use a switch statement to split out different behaviours for each type, without comparing them against a cached reference: foreach (var damageInfo in Damage) Invert the dependency, so instead of DoDamage() handling the special characteristics for each element, that behaviour instead lives in the element data, and DoDamage() can ask the element to apply its special effects on its behalf, without needing to know which element is which.Ĭreate an abstraction, where DoDamage() doesn't need to know about specific elements, just common categories of damage response. There are a few ways we can respond to this:Īccept that new elements will always require new code anyway, and hard-code the set of elements into an enumeration that's easy to check against. Now even if you can add a new element purely with data, you still need code changes to imbue it with its special characteristics. You might even be able to ship new elements in bonus content packs or mods.īut by checking for specific elements explicitly inside your DoDamage() function, you lose those benefits. ![]() in data as ScriptableObjects is that you can add/remove/update the collection of elements with pure data changes - no new code, refactoring, or re-compilation required. One of the advantages of defining your elements/damage types/etc. Is there any better way I can check for equality without having to use editor set references? Seems to me to be a huge downside of ScriptableObjects. What I would like to do is check what type of Element damage I am currently iterating in order to apply different modifiers, I know this can be done through setting up editor references and comparing against them, but that would require far too much editor setup each time and seems to me using a simple enum while less flexible would be less work overall(even to change in future).Įven setting all the references one time on a globally accessible class, removes the modularity/easy extensibility of using ScriptableObjects in the first place. OnHitObject?.Invoke(this, otherHealth.gameObject, position) private IEnumerator DoDamage(WeaponAttack attack, Health otherHealth, Vector3 position) Public DamageInfo(float damage, Element damageType)Įlsewhere in my code on the weapon I have my DoDamage function. A rather simple question, how do you check equality of a scriptable object without references?įor example, I have a weapon class that holds a list of damage types the weapon deals, which consists of a float and a ScriptableObject class (Element). ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |