Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Oliver1135 · May 18, 2018 at 02:10 PM · prefabassetbundletestingplaymode

Load and Instantiate prefab so that it can be tested in Play Mode Test

Can someone help me achieve the correct code I need in order to test my prefab:

Unity Version: 2018.1.0f2

Load a prefab from disc somehow that isn't using Resources.Load. Create an instance of the prefab (I imagine once I have the correct code to load the thing its a simple GameObject.Instantiate() call but i am likely to be wrong)


I want to be able to instantiate a prefab in a play mode test in c# code so that I can attempt testing my class. I thought this would be trivial to do so, I am finding that it is not. Reading best practices had advised me not to use Resources.Load ( https://unity3d.com/learn/tutorials/topics/best-practices/resources-folder 'Don't Use it.') and that I should use this asset bundle "thing" that I am having some difficulty using for my test.


This is as close as I have gotten which needless to say, is not close at all:

alt text


the assetBundles variable contains a list with one entry. "game" (now two "game.game") the paths variable contains a list with one entry "Assets/Spessman/Resources/Prefabs/Player.prefab" which is the correct asset I want, but I do not know how to load it so that I can instantiate based off it, which I am guessing what I need to do.


The error I am getting is:


WhenCreatingAnActorController (0.000s) --- OneTimeSetUp: Unhandled log message: '[Error] Unable to read header from archive file: Assets/Spessman/Resources/Prefabs/Player.prefab'. Use UnityEngine.TestTools.LogAssert.Expect


which I imagine is because I am meant to point at an Asset Bundle file and not a thing i want to load (guessing completely)


alt text


From some part of my mucking around I have magically conjured another of these "asset bundles" that i can't seem to find anywhere in the project called game.game that is erroneous.


Thank you for your time.

unityqimage1.png (26.0 kB)
unityqimage2.png (13.8 kB)
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Oliver1135 · May 19, 2018 at 11:49 AM

I did not find a way to do this. ugly but I have just created a test class to test the manual construction of what my prefab would be and i'm just using that, it just really sucks. if the prefab gets a lot more complex that i want to test it might be very prone to error/maintenance.


I am still kind of happy i persevered though in this dirty fix, because in part of writing my tests I have discovered some bugs and have quickly fixed them so I'm a lot happier about future refactorings being possible. Even if its very far from ideal. If I'm doing this from code anyway i might abandon the use of prefabs and instantiate from code. Not sure.

alt text

unityqimage1.png (21.3 kB)
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

109 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Is it a valid approach to check Prefab connections in OnValidate()? 1 Answer

How to modify "resources.assets" (or alternative?) 2 Answers

How do you associate a Material Picker to prefab placed in scene from AssetBundles 0 Answers

how can I export a prefab modified from fbx model? 2 Answers

PlayMode Monobehavior test 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