Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by imagoculturae · Nov 05, 2014 at 11:55 AM · resources.load

Interact with objects from Resources.Load

How do I interact with objects loaded from the resources? I have an empty objects on which I have attached a box collider, a script that rotate the object with mouseclick and finally a script to load the real object taken from the resources:

 #pragma strict
 
 public var model:String;
 function Start () {
 var instance : GameObject = Instantiate(Resources.Load(model,GameObject),Vector3.zero,Quaternion.identity);                                       
 }

Everything works well when using internal objects, but when I load from resources it will only display the object without the possibility to interact. Is there another method to interact with objects taken from the resources?

Please help! Many thanks

Comment
Add comment · Show 7
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Linus · Nov 05, 2014 at 12:37 PM 0
Share

What path are you using?

The path is relative to any Resources folder inside the Assets folder of your project, extensions must be omitted. All asset names & paths in Unity use forward slashes, paths using backslashes will not work.

http://docs.unity3d.com/ScriptReference/Resources.Load.html

avatar image imagoculturae · Nov 06, 2014 at 02:05 PM 0
Share

I don't think is a problem of the path because the object displays correctly, but I can't do anything with it :-(

avatar image Mayank Ghanshala · Nov 06, 2014 at 02:11 PM 1
Share

How you are interacting with it? Could you specify what you are doing?

avatar image imagoculturae · Nov 06, 2014 at 02:14 PM 0
Share

The above script is attached to an empty object then I have 2 more things attached in the inspector which are a box collider and a script to rotate the object with the mouse, that is it. As state, it works perfectly if I place the same obect in the scene but it does not work when loaded from resources

avatar image Mayank Ghanshala · Nov 06, 2014 at 02:17 PM 0
Share

means you made same object prefab in Resources ? Or you missed some component in it(like BoxCollider , Script)

Show more comments

3 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Bunny83 · Nov 07, 2014 at 01:34 PM

I guess your empty gameobject should be some kind of placeholder for the object you load from Resources. You might want to make it a child of your empty Gameobject once you instantiated it. Because at the moment your instantiated object is on it's own and has nothing to do with your empty gameobject:

 // [...]
     var instance : GameObject = Instantiate(Resources.Load(model,GameObject),Vector3.zero,Quaternion.identity);
     
     // make it a child of this gameobject.
     instance.transform.parent = transform;
     
     // move the child to local 0,0,0 inside the empty gameobject
     instance.transform.localPosition = Vector3.zero;
     instance.transform.localEulerAngles = Vector3.zero;

 // [...]
 
Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image imagoculturae · Nov 09, 2014 at 10:37 AM 0
Share

Hi Bunny83 Thanks a lot!!! that Solved the problem. Now I have this:

 function On$$anonymous$$ouseDown(){
     
 var instance : GameObject = Instantiate(Resources.Load(model,GameObject),Vector3.zero,Quaternion.identity);
     
     // make it a child of this gameobject.
 instance.transform.parent = transform;
     // move the child to local 0,0,0 inside the empty gameobject
 instance.transform.localPosition = Vector3.zero; instance.transform.localEulerAngles = Vector3.zero; 
     }
    

Dou you know how can I implement it so that everytime I click it will loads a new objects and it destroy the previuos one? Sorry but I am not much of a programmer, I can go a bit trough script but I can't really think in program$$anonymous$$g langauages.

avatar image Bunny83 · Nov 10, 2014 at 09:34 PM 0
Share

@paganic: Sorry, but your question was about how to interact with an instantiated object. In your code you only have one model name string so without having an array or list of (possible) model names you won't get anywhere.

Anyways this is something that doesn't belong to this question. Ask a new question and provide more details on your specific problem there. If this question is solved, don't forget to tick an answer.

avatar image imagoculturae · Nov 10, 2014 at 11:41 PM 0
Share

Ok thanks a lot I'll do that

avatar image
0

Answer by Chamkey · Nov 06, 2014 at 06:10 PM

I had a somewhat similar problem just 2 weeks ago. I'm assuming that the interactivity comes from a gameobject that you define. As in drag and drop from the hierarchy onto your script?

The problem is that when you instantiate this object the script doesn't know which object its behaviour is coming from.

The normal object I'm assuming is the child of the empty GO.

 var model: String;
 var emptyObject: GameObject;
 
 function Start()
 {
    var thisObject: Gameobject.Instantiate(Resources.Load(model, GameObject), Vector3.zero, Quaternion.identity);
    //please tag your empty with whatever you want. I'm just using Parent
    emptyObject = GameObject.FindObjectWithTag("Parent")
 
    thisObject.transform.parent = emptyObject.transform;
 }
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by imagoculturae · Nov 06, 2014 at 07:30 PM

I partially solved the problem with this:

 #pragma strict
 
 public var model:String;
 function Start () {
 var instance : GameObject = Instantiate(Resources.Load(model, GameObject),Vector3.zero,Quaternion.identity);
 instance.AddComponent(BoxCollider);                                     
 }

but I don't really like the idea of having to create a box collider from script I simply would like to access the one I create in the inspector

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Resources.Load for .Dat ? 1 Answer

Resources.Load() or Prefab manager? 1 Answer

Resources.Load from TextAsset string 1 Answer

Resources.Load makes Featureless Oddity 0 Answers

Resources.load absolute path 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges