1. The space forums use a separate registration system from the main virtual world. To comment on these forums, you need to create a separate forum account.
    Dismiss Notice
  2. Hey there, we have two Skype groups for space early users - if you're creating content, or need help, feel free to join in either the the beginners or advanced users groups.
    Dismiss Notice

Bug Report GetResource Errors with Materials

Discussion in 'Bug Reports' started by AshaSekayi, Dec 3, 2017.

Share This Page

  1. AshaSekayi

    By:AshaSekayiDec 3, 2017
    Member

    Joined:
    Dec 20, 2016
    Messages:
    49
    Likes Received:
    5
    So, I've added a material to a Resource slot in my script.

    In the script, I wrote:
    plantMat = Space.GetResource("plantMat_PBR")

    Error:
    Script error while executing script attached to Sphere: chunk_0:(5,0-44): cannot access field GetResource of userdata<SineSpace.Scripting.Scene.SScript> possibly at Line 5: plantMat = Space.GetResource("plantMat_PBR");
    UnityEngine.Debug:LogError(Object, Object)
    ScriptingRuntimeBaseInternal:LogScriptException(ScriptRuntimeException)
    ScriptingRuntimeBaseInternal:StartExecution()
    :MoveNext()
    UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)

    Then, I tried:
    plantMat = Space.GetResource("plantMat_PBR").AsMaterial
    That didn't work either.

    After that, I tried accessing Space.Resources[0]. That worked with .name but it gave a "userdata<SResource>" error when I tried to use the variable with SMaterial methods.
     
  2. Torgon Woodget

    By:Torgon WoodgetDec 3, 2017
    Member

    Joined:
    Jun 17, 2017
    Messages:
    83
    Likes Received:
    2
    Is "plantMat_PBR" the name you gave your material in the resources list (first field), or the name of the material (second field)? You have to take the first one....
     
  3. AshaSekayi

    By:AshaSekayiDec 5, 2017
    Member

    Joined:
    Dec 20, 2016
    Messages:
    49
    Likes Received:
    5
    It's the name I gave the material in the name slot for resources in the script.
     
  4. Adam

    By:AdamDec 5, 2017
    Developer
    Staff Member Moderator

    Joined:
    Aug 21, 2014
    Messages:
    630
    Likes Received:
    113
    Actually that error seems to be implying the function 'GetResource' is missing entirely.

    The GetResource function is new - I'd suggest grabbing a newer editor pack if it's missing.

    Finally, for using a SResource as a SMaterial, you need to use one of the 'As' properties, there's a '.AsMaterial' property on SResource to convert it. (no implicit typecasting built-in just yet)
     
  5. AshaSekayi

    By:AshaSekayiDec 5, 2017
    Member

    Joined:
    Dec 20, 2016
    Messages:
    49
    Likes Received:
    5
    I'm using Unity 5.6.3p1 and Editor Pack 11.0.1. Is there a more up-to-date EP?

    I used this test code in a clean install of EP 11.0.1:

    GetResourceProblem.PNG

    And, I received this error:
    Script error while executing script attached to Cube: chunk_0:(4,0-45): cannot access field GetResource of userdata<SineSpace.Scripting.Scene.SScript> possibly at Line 4: mat = Space.GetResource("demoMat").AsMaterial;
    UnityEngine.Debug:LogError(Object, Object)
    ScriptingRuntimeBaseInternal:LogScriptException(ScriptRuntimeException)
    ScriptingRuntimeBaseInternal:StartExecution()
    :MoveNext()
    UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)