Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

instantiate a script that is not attached to a GO?

Discussion in 'Scripting' started by tomjoad, May 4, 2007.

  1. tomjoad

    tomjoad

    Joined:
    Apr 14, 2007
    Posts:
    37
    Anyone know if there is a way to instantiate a script that is not attached to a game object? I'm used to working in Director where I can create instances of any script on the fly and I'm trying to find a comparable Unity technique.

    Specifically, I want to create a wrapper for the WWW class so I can instantiate multiple objects to do web operations and have them call back when they are complete. The reason for this is I want to have several www operations going on at the same time and the 'yield' part is getting confusing.
     
  2. shaun

    shaun

    Joined:
    Mar 23, 2007
    Posts:
    728
  3. tomjoad

    tomjoad

    Joined:
    Apr 14, 2007
    Posts:
    37
    thanks - I've started digging around in that but it's still not working. I am trying to instantiate an object and then call some functions in it:

    Code (csharp):
    1. w = ScriptableObject.CreateInstance("rp WWW class");
    2.         www_array.push(w);
    3.         w.SetCallback(gameObject, "webOpComplete", www_array.length);
    4.         w.StartLoad(URL_array[UrlCounter]);
    I get errors that ""the script class needs to derive from a ScriptableObject" along with "SetCallabck is not a member of UNityEngine.ScriptableObject"

    Am I even close with my usage or should I go back to 0?


    :(
     
  4. tomjoad

    tomjoad

    Joined:
    Apr 14, 2007
    Posts:
    37
    Quoting myself... how pathetic is that! :oops:

    I'm still trying to make my way with using the 'ScriptableObject' function. Still getting the errors mentioned above. What I am trying to do is create instances of a script, call some functions on the instances, set some callbacks, and then store the instance in an array until the callback is called.

    I'm used to working in this style in Director and trying to come up with an equivalent (or equal/better) method in Unity. The reason for the callback method is that it allows the instances to do their tasks without having to monitor them.

    Can someone tech out the issue with my use of 'ScriptableObject'?

    thanks!

    --Roy
     
  5. hsparra

    hsparra

    Joined:
    Jul 12, 2005
    Posts:
    750