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
0
Question by Damocles · Sep 18, 2012 at 12:08 PM · prefabsparticle systemresources.load

prefab loading via resources forced to inactive

I'm having an issue with loading prefabs via Resources.Load. For some reason, the prefab is set to active=false when the prefab is instantiated. Also, the prefab instance doesn't show up in scene mode. Here's the code I'm using to instantiate the item:

     public void setItemType(string name)
     {
         name = "Prefabs/PFX-" + name + "-" + Game.room.curThemeName;

         Debug.Log(name);
         pfxChild = (GameObject)Resources.Load(name);
         pfxChild.active = true;
         Debug.Log(pfxChild + "  pos:"+pfxChild.transform.position + "  active:"+pfxChild.active);
     }

The final debug log from that code outputs:

"PFX-water drops-normal (UnityEngine.GameObject) pos:(393.3, 0.0, 401.2) active:False"

The prefabs seem fine - I can drag them into the scene view and they work correctly. When I instantiate through Resources.Load, the object exists as far as the script is concerned, but it doesn't appear in game or in the paused scene view. The most baffling thing though is that the object is set to active=false, even though I explicitly set it to true.

Is it somehow related to it being a particle system prefab? The prefab itself consists solely of a game object with a particle system component.

Anyone have any ideas why this is happening?

Comment
Add comment
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

2 Replies

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

Answer by Damocles · Sep 18, 2012 at 04:02 PM

Ah, found the problem. Pretty obvious really - Resources.Load simply loads the resource for use, it doesn't instantiate it. I changed the line:

pfxChild = (GameObject)Resources.Load(name);

to:

pfxChild = (GameObject)GameObject.Instantiate((GameObject)Resources.Load(name));

and it worked as expected.

Comment
Add comment · Show 2 · 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 The-Arc-Games · Sep 18, 2012 at 04:04 PM 0
Share

Hah. Well done. Thanks for posting back.

Now please accept your answer as the solution, so that this can be used properly by others :)

avatar image Damocles · Sep 18, 2012 at 07:21 PM 0
Share

d'oh, forgot to hit the tick :) Thanks for re$$anonymous$$ding me.

avatar image
0

Answer by The-Arc-Games · Sep 18, 2012 at 01:41 PM

It is quite probable that your problem is related to SCALE. Make sure that, in the project, the model Mesh Scale is set to 1.

FBX defaults to 0.01 scale, so it's basically invisible in respect to 'normal' objects.

Comment
Add comment · Show 2 · 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 Damocles · Sep 18, 2012 at 01:56 PM 0
Share

There is no mesh involved here. The prefab is an empty game object with a particle system component. There is no mesh to see, only particles. Plus I have an editor script that causes all meshes to import at 0.1 scale ins$$anonymous$$d of 0.01, because I got sick of having to manually change every mesh.

avatar image The-Arc-Games · Sep 18, 2012 at 04:01 PM 0
Share

Curious issue. Have you tried the same loading routine with a different prefab, made out of primitives perhaps?

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

11 People are following this question.

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

Related Questions

Update a Prefab in the Resources Folder in Edit-Mode by a Script 0 Answers

how to instantiate saved objects back into game 1 Answer

How to load a prefab / object from a http source (e.g. REST API)? 2 Answers

Resource Load Prefab 0 Answers

About to gut my use of the Resources folder. What are the best practices going forward? 1 Answer


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