Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by obsidianz · Nov 23, 2020 at 11:14 AM · scriptableobject

Ability System with ScriptableObject

I'm trying to make a ScriptableObject Ability System for my grid based game.

 public class Skill : ScriptableObject
 {
     public SkillDamageProperty[] damageProperties;
 
     public void ApplySkill(Vector2Int position)
     {
         MapPositions positions = GameObject.Find("Map").GetComponent<MapPositions>();
 
         // Damage
         for (int i = 0; i < damageProperties.Length; i++)
         {
             Vector2Int target = position + damageProperties[i].position;
 
             GameObject obj = positions.GetPosition(target);
             if (obj == null) continue;
             Stats entity = obj.GetComponent<Stats>();
             if (entity == null) continue;
             entity.Health -= damageProperties[i].damage;
         }
     }

As this class is a Scriptable Object I can create multiple skills and select which positions take damage in the inspector.


Beside damage, I want the skills to apply other effects to the enemies (like stunning, pushing, setting them on fire, etc). This effects would also be assigned to each skill in the inspector.

Now here's my problem: different effects may require diferent arguments (burning requires int duration, pushing requires Vector2Int direction, and so on). How could I assign diferent types of arguments in the ispector?


I thought about 2 ways of doing this, but both ways have problems:

  • I could create a class like I did for the damageProperties and then use subclasses for each type of effect. The problem here is that subclass variables don't show up in the inspector.

  • My other Idea was to make a UnityEvent and assign one function to each effect in the inspector. Here I have 2 problems: I can only pass one argument in the inspector (and I may need more arguments for some effects) and if I pass the arguments in the inspector I cannot pass the entity that's going to get it when I call event.Invoke();

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by $$anonymous$$ · Nov 23, 2020 at 01:26 PM

Check this videos out

Inheritance

Overriding Fuctions

You can make a script for each ability deriving from a ability script

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image obsidianz · Nov 23, 2020 at 08:39 PM 0
Share

$$anonymous$$y game is grid based. The only thing that changes between abilities is the positions on the grid that that take damage.

Right now I have 2 types of Effects that I want some abilities to use: Stun and Push. I could create a subclass for using the Stun effect, other for using Push and another for using both.

The problem with that method is that I would have to double the number of subclasses everytime I wanted to add a new type of Effect.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

142 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Unity 2D: How to keep player within boundary and more in the picture below 2 Answers

Confused about custom GameObjects,Custom GameObject confusion 0 Answers

Auto-refresh assets after changing scriptable object 0 Answers

Animate ScriptableObject field? Why not? 0 Answers

Can't assign rigidbody/transform variables to an extension class asset 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges