Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Join us on Dec 8, 2022, between 7 am & 7 pm EST, in the DOTS Dev Blitz Day 2022 - Q&A forum, Discord, and Unity3D Subreddit to learn more about DOTS directly from the Unity Developers.
    Dismiss Notice
  3. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

Error 1061, relative SetActive.

Discussion in 'Editor & General Support' started by PortcoastDT, Feb 11, 2020.

  1. PortcoastDT

    PortcoastDT

    Joined:
    Jun 17, 2019
    Posts:
    8
    i'm building a application to simulation a construction in my thesis. Project have the button Next and Previous to appear and hide object sequence alternately. I use array function and Reorderable library. But i meet error

    "Assets/ReorderableList/Example/NestedExample.cs(25,28): error CS1061: 'NestedExample.ExampleChildList' does not contain a definition for 'SetActive' and no accessible extension method 'SetActive' accepting a first argument of type 'NestedExample.ExampleChildList' could be found (are you missing a using directive or an assembly reference?)"

    I try to fix the code in (SetActive of Appear Model...) but it's not work. Can Anyones help me or give me some advices? Thanks Advance. Sorry, cause i just started coding!

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.Reorderable;
    5. using UnityEngine.UI;
    6.  
    7. public class NestedExample : MonoBehaviour
    8. {
    9.     public Button NextButton;
    10.     public Button PreviousButton;
    11.     [Reorderable]
    12.     public ExampleChildList [] AppearModel;
    13.     [Reorderable]
    14.     public ExampleChildList [] HideModel;
    15.  
    16.  
    17.     [System.Serializable]
    18.     public class ExampleChildList : ReorderableArray<GameObject>
    19.     {
    20.     }
    21.     private int index;
    22.  
    23.     public void PreviousModel()
    24.     {
    25.         // Hide current model
    26.         AppearModel[index].SetActive(false);
    27.        
    28.  
    29.         index--;
    30.         if (index < AppearModel.Length - 1)
    31.         {
    32.             NextButton.interactable = true;
    33.         }
    34.     }
    35.  
    36.     public void NextModel()
    37.     {
    38.         index++;
    39.        // Show next model
    40.         AppearModel[index].SetActive(true);
    41.      
    42.  
    43.         if (index == AppearModel.Length - 1)
    44.         {
    45.             NextButton.interactable = false;
    46.         }
    47.      
    48.     }
    49. }
    50.  
     
    Last edited: Feb 12, 2020
  2. streeetwalker

    streeetwalker

    Joined:
    Jun 4, 2013
    Posts:
    327
    Is ExampleChildList a list of GameObjects? Then you may need to cast the variable
    Code (CSharp):
    1. (GameObject) AppearModel[index].SetActive(false);
    Otherwise, we need to know what type of data the list holds.
     
  3. PortcoastDT

    PortcoastDT

    Joined:
    Jun 17, 2019
    Posts:
    8
    Thanks you for replying me soon! Yes, GameObject is a child of ExampleChildList.
    I follow your instruction, but have add error "Assets/ReorderableList/Example/NestedExample.cs(25,9): error CS0201: Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement"

    The data, that the list holds is GameObject (i drag these model gameobject from Hierarchy). I tried removing in code from line 19 to 46 and code run, i attached screenshot below. Thanks!!!

    upload_2020-2-12_9-51-35.png
     
  4. streeetwalker

    streeetwalker

    Joined:
    Jun 4, 2013
    Posts:
    327
    Sorry, my bad - you'd need to cast in an assignment statement. Try this:

    Code (CSharp):
    1.  
    2.  
    3. GameObject g = (GameObject) AppearModel[index];
    4. g.SetActive(false);
    5.  
    6.  
    Make sure you actually dragged the game objects to your inspector! - because those are empty in you graphic above. (you wrote that you did... but just to be sure)
     
  5. PortcoastDT

    PortcoastDT

    Joined:
    Jun 17, 2019
    Posts:
    8
    Thanks for your enthusiasm. Game objects can still be dragged into the inspector bar. I have tried your way and a few more, but still haven't ast in an assignment statement for GameObject. Still the same error as the original. My coding ability is still poor, I will try harder, hope to fix this code in near future