Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Resource.Load Question

Discussion in 'Scripting' started by Phobiegames, Nov 20, 2017.

  1. Phobiegames

    Phobiegames

    Joined:
    Apr 3, 2017
    Posts:
    113
    so i have a simple test script to change the animator during runtime so that i can add multiple skins to a 2d character but keep its animations, the animator im trying to access is in the assets folder but it doesn't seem to be working

    Script:
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class SkinSwitcher : MonoBehaviour {
    6.  
    7.  
    8.     public Animator BirdSprites;
    9.  
    10.  
    11.     // Use this for initialization
    12.     void Start () {
    13.         BirdSprites = GetComponent<Animator>();
    14.  
    15.         BirdSprites.runtimeAnimatorController = Resources.Load("Assets/Bird1") as RuntimeAnimatorController;
    16. }
    17.    
    18.     // Update is called once per frame
    19.     void Update () {
    20.        
    21.     }
    22. }
    23.  
     
  2. Phobiegames

    Phobiegames

    Joined:
    Apr 3, 2017
    Posts:
    113
  3. Akzafield

    Akzafield

    Joined:
    Aug 20, 2017
    Posts:
    17
    Stupid question but:
    Is Assets/Bird1 located in Resources Folder?
    Can Assets/Bird1 be loaded as a Object?
     
  4. Phobiegames

    Phobiegames

    Joined:
    Apr 3, 2017
    Posts:
    113
    In the project folder its simply an animator controller thats just in the assets folder
     
  5. Akzafield

    Akzafield

    Joined:
    Aug 20, 2017
    Posts:
    17
    https://docs.unity3d.com/462/Documentation/ScriptReference/Resources.html
    "All assets that are in a folder named "Resources" anywhere in the Assets folder can be accessed via the Resources.Load functions. Multiple "Resources" folders may exist and when loading objects each will be examined."
    https://docs.unity3d.com/ScriptReference/Resources.Load.html
    "The path is relative to any Resources folder inside the Assets folder of your project"

    (Resources.Load need a Resource folder to be able to Load a file)
     
  6. Phobiegames

    Phobiegames

    Joined:
    Apr 3, 2017
    Posts:
    113
    Wow, thank you so much, I feel like an idiot though haha.