• 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 roroco · Nov 30, 2017 at 12:41 PM · scripting problemtesting

How to get gameobject in another scene in play mode test script

when i use following test script

     for (int i = 0; i < SceneManager.sceneCount; i++)
     {
         var s = SceneManager.GetSceneAt(i);
         Debug.Log($"s.path:{s.path}");
     }

there are only exist test scene: Assets/InitTestScene636476709590757340.unity, I hope get scene, for ex, Assets/Scene/s.unity, how should i do I try SceneManager.GetSceneByPath("Assets/Scene/s.unity") but it return null(I'm sure this scene file is exist)

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
1

Answer by roroco · Nov 30, 2017 at 02:34 PM

My tmp solution is: drag object to Resources/ dir, and load it in test script

here is my code:

 [UnityTest]
 public IEnumerator NewPlayModeTest1WithEnumeratorPasses()
 {
     var c = MonoBehaviour.Instantiate((GameObject) Resources.Load("Cube"));
     c.transform.Translate(new Vector3(0, 0, 0));
     yield return new WaitForSeconds(1);
     c.transform.Translate(new Vector3(2, 0, 0));
     yield return new WaitForSeconds(1);
     c.transform.Translate(new Vector3(0, 2, 0));
     Assert.True(true);
 }

here is my full code

here is result:

alt text


t.gif (290.7 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
avatar image
0

Answer by mafima · Nov 30, 2017 at 01:28 PM

Ctrl - shift - B. now add the current scene to your buildindex. then use SceneManger.LoadScene(id); in that case id is 1 if you want to load the other scene. could you explain more in detail what you want to do?

Comment
Add comment · Show 1 · 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 roroco · Nov 30, 2017 at 02:33 PM 0
Share

even i load scene, TheScene.isLoaded is always false, it means scene.GetRootGameObjects() count is 0, so I still cannot get object in another scene

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

127 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 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

i need help on this script can anybody figure this out? 0 Answers

The type or namespace name `SceneManagment' does not exist in the namespace 1 Answer

How to access classes written in Assembly-CSharp inside Play mode Test assembly? 0 Answers

Testing buttons in PlayMode Tests 1 Answer

Function deleting string by itself. 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges