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 Jack-Idealits · Aug 22, 2020 at 10:58 PM · editortilescriptable object

Trouble editing scriptable tiles in Unity Editor

Greetings,

I am making a tile-based game akin to Advance Wars, where terrain features hinder the movement of different units to different extents (e.g. the movement cost of a forest tile is 2 for ground units, but only 1 for air units). I use A* pathfinding for my project.

My plan is as follows:

  1. The tiles should "know" their movement costs for each unit type.

  2. The pathfinding algorithm should "know" what type of unit is accessing it; it then "asks" the tiles what their movement costs should be while exploring neibouring tiles to find a shortest path for the unit.

Here is the realization of 1, using custom, scriptable tiles:

  [CreateAssetMenu(fileName = "New GameTile", menuName = "Tiles/GameTile")]
     
     public class GameTile : Tile
     {
         public int[] movementCostReference = new int[3]; //(cost_ground, cost_amphibious, cost_air)
         
         //Other properties
     }

Here's the realization of 2, a part of the A* pathfinding algorithm:

 private void ExamineNeighbours(int movementType, List<GameTile> neighbours, GameTile current)
     {
         for(int i = 0; i < neighbours.Count; i++)
         {
             GameTile neighbour = neighbours[i];
             /*neighbour is from GameTile class; it "knows" its movement costs corresponding to different unit types*/
             int G = neighbour.movementCostReference[movementType];
 
             //Proceed to calculate G, H, F values used for determining shortest path
         }
     }
 

I believe the logic is correct, but when I assign movement costs to the scriptable tiles in Unity Editor, use SetTile method to instantiate the scriptable tiles, then run the pathfinding, the movement cost is 0 for all tiles and all unit types. It seems like the values assigned via the editor are simply ignored, leaving everything 0 by default.alt text

As an experiment, I tried adding a "public int test = 3" variable; accessing the variable during runtime always returned 3, even if I gave it different values in the editor (as in the above screenshot).

What is the problem here? Should I not use SetTile to instantiate custom tiles? Should I not use scriptable objects as tiles? Or am I just missing something else?

无标题.png (26.4 kB)
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

0 Replies

· Add your reply
  • Sort: 

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

132 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

Related Questions

How can I find all instances of a Scriptable Object in the Project (Editor) 3 Answers

In-editor object movement restriction 2 Answers

ScriptableObject not saving data to asset 2 Answers

Auto Texture Tiling Script Problem 0 Answers

Scriptable Object in Editor vs in Build 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