Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
1
Question by InMyCode · May 12, 2017 at 12:10 PM · c#unity 5interface

'Node' does not implement interface member 'interfaceNameHere'

I'm creating an A* pathfinding algorithm with HEAP(optimizing) where I've created an interface called IHeapItem. When I try to use it with my "Node" Class it throws an compile error: "`Node' does not implement interface member `IHeapItem.HeapIndex.get'"

Do you guys know how I can solve this error?

Node Class

 using System;
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class Node : IHeapItem<Node>{  //Error here
 
     public bool walkable;
     public Vector3 worldPosition;
     public int gridX;
     public int gridY;
 
     public int gCost;
     public int hCost;
     private int heapIndex;
 
     public Node parent;
 
     public int fCost
     {
         get { return gCost + hCost; }
     }
 
     public int Heapindex
     {
         get
         {
             return heapIndex;
         }
         set
         {
             heapIndex = value;
         }
     }
 
     public Node(bool _walkable, Vector3 _worldPos, int _gridX, int _gridY )
     {
         walkable = _walkable;
         worldPosition = _worldPos;
         gridX = _gridX;
         gridY = _gridY;
     }
 
     public int CompareTo(Node nodeToCompare)
     {
         int compare = fCost.CompareTo(nodeToCompare.fCost);
         if (compare == 0)
         {
             compare = hCost.CompareTo(nodeToCompare.hCost);
         }
         return -compare;
     }
 }

HEAP Class:

 using System;
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class Heap<T> where T : IHeapItem<T>{
 
     T[] items;
     int currentItemCount;
 
     public Heap(int maxHeapSize)
     {
         items = new T[maxHeapSize];
     }
 
     public void Add(T item)
     {
         item.HeapIndex = currentItemCount;
         items[currentItemCount] = item;
         SortUp(item);
         currentItemCount++;
     }
 
     public T RemoveFirst()
     {
         T firstItem = items[0];
         currentItemCount--;
         items[0] = items[currentItemCount];
         items[0].HeapIndex = 0;
         SortDown(items[0]);
         return firstItem;
     }
 
     public void UpdateItem(T item)
     {
         SortUp(item);
     }
 
     public int Count
     {
         get
         {
             return currentItemCount;
         }
     }
 
     public bool Contains(T item)
     {
         return Equals(items[item.HeapIndex], item);
     }
 
     private void SortDown(T item)
     {
         while (true)
         {
             int childIndexLeft = item.HeapIndex * 2 + 1;
             int childIndexRight = item.HeapIndex * 2 + 2;
             int swapIndex = 0;
 
             if (childIndexLeft < currentItemCount)
             {
                 swapIndex = childIndexLeft;
 
                 if (childIndexRight < currentItemCount)
                 {
                     if (items[childIndexLeft].CompareTo(items[childIndexRight]) < 0)
                     {
                         swapIndex = childIndexRight;
                     }
                 }
 
                 if (item.CompareTo(items[swapIndex]) < 0)
                 {
                     Swap(item, items[swapIndex]);
                 }
                 else
                 {
                     return;
                 }
             }
             else
             {
                 return;
             }
         }
     }
 
     private void SortUp(T item)
     {
         int parentIndex = (item.HeapIndex - 1) / 2;
 
         while (true)
         {
             T parentItem = items[parentIndex];
             if (item.CompareTo(parentItem) > 0)
             {
                 Swap(item, parentItem);
             }
             else
             {
                 break;
             }
             parentIndex = (item.HeapIndex - 1) / 2;
         }
     }
 
     private void Swap(T itemA, T itemB)
     {
         items[itemA.HeapIndex] = itemB;
         items[itemB.HeapIndex] = itemA;
 
         int itemAIndex = itemA.HeapIndex;
         itemA.HeapIndex = itemB.HeapIndex;
         itemB.HeapIndex = itemAIndex;
     }
 }
 
     public interface IHeapItem<T> : IComparable<T>
 {
     int HeapIndex
     {
         get;
         set;
     }
 }



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
3
Best Answer

Answer by Baste · May 12, 2017 at 02:50 PM

You misspelled HeapIndex in Node!

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

8 People are following this question.

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

Related Questions

Start function dont work 1 Answer

OnPostprocessBuild and Unity Cloud 0 Answers

How to get input of VR head movement??!! 1 Answer

Fade out / fade in scene w/ loading screen 0 Answers

error CS0201 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