Script Initialization Order

  • Hey Naomi,

    Your code looks right and your situation definitely sounds like a bug, but I'm having trouble reproducing it in a test project. While I keep looking into it, can you try a small change and see if it helps?

    Instead of referencing the SceneObjects and using getFirstComponent(), you can reference the ScriptComponents directly like this:

    // @input Component.ScriptComponent[] hornScripts

    Then, you can use script.hornScripts directly instead of building the list using getFirstComponent(). I hope this can fix the problem if it's somehow caused by the references becoming invalid. Please let me know if this helps!

    Jacob

    Comment actions Permalink
  • Hi Jacob,

    Thanks so much for the response! I'll give this a try. I had actually happened upon this during some further testing, realizing that this didn't run any errors:

    // @input Component[] horns
    // @input ScriptComponent[] boppers

    ...and submitted, still to no avail. I have just resubmitted with both of the inputs as ScriptComponent[] instead of using Component[] for one of them, so we'll see if that works. Of note, in the dialog box when I attach the scene components to the proper Script inputs, I am allowed to attach SceneObjects, but I can't expand those to select their components, even though the script input type is asking for a ScriptComponent.

    That's supported by some more evidence: I had some print statements in this newest version:

    for(var i = 0; i < script.boppers.length; i++) {
    if (script.boppers[i] == undefined) {
    bopScript[i] = script.getSceneObject().getChild(i+8).getFirstComponent("ScriptComponent");
    } else {
    bopScript[i] = script.boppers[i].getFirstComponent("ScriptComponent");
    }
    print(script.boppers[i].name+" s.b;bS "+bopScript[i].name);
    }

    ...and these, in all iterations, for both horns and boppers, return the name of the scene object that was @input, followed by "Script". So @inputting the SceneObjects as ScriptComponents definitely still seems to reference them as SceneObjects, not directly referencing the scripts like you mentioned.

    Here's the full project if you'd like to play around in a non-test environment:
    https://www.dropbox.com/s/ul4lphvr3flzfbm/Grad19_v7i_LSPROJ.zip?dl=0

    Thanks again!!

    Comment actions Permalink
  • Hey it's live!

    Seems changing it from Component to ScriptComponent did the trick!

    Comment actions Permalink
  • Hey Naomi,

    Glad it's working now!

    Just a note, you should use "Component.ScriptComponent" as the input type instead of just "ScriptComponent", and using "Component" by itself isn't supported. I think that's where the strange behavior is coming from. I'm pretty surprised you were able to do that, I get error messages when I try. Are you using the Windows or Mac version?

    Thanks!

    Comment actions Permalink
  • That definitely sounds odd. I am using Windows. I also had a coworker QA test various iterations of the "final" lens on Mac (no errors found there either),

    Not sure how relevant this is but another coworker designed the confetti particles on a mac as well. I opened his LSPROJ file in Windows to make a prefab, which I then imported into my main Windows project.

    If you happen to find more insight on why importing the objects as SceneObjects wasn't working, I'd love to learn if there is anything I can do about that in the future! Thanks again for your help.

    Comment actions Permalink
  • Hey Naomi,

    It looks like there's a bug where changing an array property to an invalid type continues to work, instead of giving an error message and not drawing the script UI. So I think what happened was:

     

    1. There was an //@input SceneObject[] list

    2. This was changed to an unsupported type like //@input Component[] list

    3. Due to this bug, because the new type was invalid, the list continued acting as the last valid type (SceneObject)

     

    Hope this makes sense! We will try to get this bug fixed as it definitely can be confusing. To avoid this in the future you can make sure typenames are valid by temporarily adding a new property to test them like:

    // @input Component test 

    This should (correctly) give an error message when the script UI is drawn. This bug only occurs when switching an already existing array from a valid type to an invalid type.

    Let me know if you have any more questions!

     

    Comment actions Permalink
  • Interesting! I'm glad to have that in my bag o debugging tricks!

    I'm still confused as to why that would affect the initial problem:

    // @input SceneObject[] horns
    // each of the horns is a SceneObject that is a child of this SceneObject

    var hornScript = []

    function initialize() {
    // runs through the scene-input objects array and makes an array of their ScriptComponents for easier access
    for(var i = 0; i < script.horns.length; i++) {
    hornScript[i] = script.horns[i].getFirstComponent("ScriptComponent");
    }
    }

    It seems like this section of code is using a valid type, SceneObject, and a valid function to access the ScriptComponent. As a refresher, this function was bound to "TurnOnEvent". Upon opening the LSProj, a Reference to Undefined ScriptComponent error sometimes ran from a reference to hornScript[] members within a function bound to "MouthOpenedEvent". It ran before a mouth was opened, and it definitely seems like a runtime-specific error. After a lens reset, the lens always worked perfectly, but was still unsubmittable.

    I've added a version of the project with that older setup as shown above if that may be of assistance (v7g): https://www.dropbox.com/sh/wcqg1niwt0artyx/AACVbeOW4hUykrmhY6cLynnta?dl=0

    Comment actions Permalink
Have a comment?

Please sign in to leave a comment.

We're here to help! We just need a little bit of information...

What system are you using?

Have you downloaded the latest version of Lens Studio?

Please download the latest version of Lens Studio. If you still run into this issue, please come back and report it!

Is this issue causing Lens Studio to crash?

What system do you run Lens Studio on?

Version

Graphics

Follow the next steps to help us solve your issue:

  • Copy and paste this text into your TerminalCommand Window
    open ~/Library/Preferences/Snap/Lens\ Studio/ %LOCALAPPDATA%\Snap\Lens Studio Copy Text
  • Press ReturnEnter to run the command. The Lens Studio folder will automatically open
  • Prepare to upload your files: zip the "Log" Folder by right-clicking and choosing "compress."
    Locate the Log.txt file right above it.

    Attach a screenshot of the issue:

Name:

Email:

What is this most relevant to?

Please enter a brief description of your issue:

Thanks for submitting this issue.

Unfortunately, it's likely due to the operating system or hardware you're using – since they don't meet the system requirements for Lens Studio.

Still, we hear you loud and clear, and are logging the issue in case there's ever a workaround we can provide!

Minimum Requirements

Operating System: Windows 10 (64 bit); MacOS 10.11+

Hardware: Minimum of Intel Core i3 2.5Ghz or AMD Phenom II 2.6Ghz with 4 GB RAM; Intel HD Graphics 4000 / Nvidia GeForce 710 / AMD Radeon HD 6450 or better; screen resolution of 1280x768 or higher

We'll try to resolve this issue as soon as possible. Thanks for letting us know about it!

Keep an eye out for a followup email from us. We may have a couple more questions for you, or we might already have a solution to offer.

Happy creating!