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
1
Question by GRaveChilD · May 06, 2021 at 11:42 AM · editor-scriptingscriptableobjecteventscriptable objectfunction call

Dynamic skill system with scriptable objects

I'm trying to make a dynamic skill system in which you can easily create new skills from the editor.

 [CreateAssetMenu(fileName = "NewProjectileSkill", menuName = "ScriptableObjects/New Projectile Skill")]
 public class ProjectileSkill : Skill
 {
     public GameObject prefab;
     public float speed;
     public float damage;
     public float cooldown;
     public float energyCost;
 }

 public class Skill : ScriptableObject
 {
         public bool enabled;
         public string skillName;
 }

Currently what I'm trying to achieve is to expose another field in the editor to which I can assign a function (created in a separate script) which would have atleast two parameters. That function later on will be called when the said skill collides with another object.

My question here is how can I smartly achieve this?

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by pietro0games · Jun 09, 2021 at 12:50 AM

You "can't" achieve this. If you create any field that is a script class of your own, you will notice that dragging a script into it won't work. You can only drag assets to fields, to create an asset of a script is needed to create a prefab with a GameObject. Using a Monobehavior prefab inside the ScriptableObject looses almost all the reasons of using a ScriptableObjec. I really wanted to achieve this too

Comment
Add comment · 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
0

Answer by eneIr · Jun 09, 2021 at 02:39 AM

Actually you can do it, but you will have to use MonoBehaviour script. You can still use both MonoBehaviour and ScriptableObject script together, with ScriptableObject to store other data and MonoBehaviour script to store the function with parameters. Add the code below to your MonoBehaviour script and in the editor you can drag and drop a public void() function in and you can access that function if you want, just like when you add onClick() function to an UI button. Hope that fits what you need!

     using System;
     using UnityEngine;
     using UnityEngine.Events;
     
     public class YourScript : MonoBehaviour
     {
         [Serializable]
         public class YourFunction : UnityEvent { }
     
         [SerializeField]
         private YourFunction yFunction = new YourFunction();
         public YourFunction Y_Function { get { return yFunction; } set { yFunction = value; } }
     }


Comment
Add comment · 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

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

134 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

Related Questions

Scriptable Objects with editable functions 1 Answer

target of triggers on eventtrigger is null when reload scriptableObject how to fix it? 0 Answers

Confused about custom GameObjects,Custom GameObject confusion 0 Answers

Unity Duplicate Event 5 Answers

Get list of all "Action" classes 1 Answer


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