Dawit
Dawit

Reputation: 642

Delay cmd -executeMethod or Set Active scene from cmd

I have BaseEmptyScene in Testproject1. BaseEmptyScene does not have any GameObjects. The only thing this project and scene has is a c# script with static method called bang().

I have a second Project called Sphere with Scene called 'Sphere'. It has basic GameObjects Sphere and Cube in it, no script. I went ' Assets > Export Package ' and exported everything to SphereCube.unitypackage

Here is my command line for executing method bang() after importing SphereCube.unitypackage into Testproject1.

C:\Program Files\Unity\Editor>Unity.exe -projectPath SomePath\TempProj -importPackage Path\SphereCube.unitypackage -executeMethod TestClass.bang 

This commands opens unity , imports the package and execute the method bang fine. see unity command Line Argument doc

My problem is i cant tell unity to execute the method AFTER it finished importing the package. Here is what bang() looks like - currently it always displays scene count as 1. It should be 2 as i can see two scenes in Assets folder once the import is done (the empty scene with 1 script and the imported SphereCube scene)

private static void bang(){
...

        sw.WriteLine("Scene Count = " + SceneManager.sceneCount);
        sw.WriteLine("Active Scene = " + SceneManager.GetActiveScene().name + " " + SceneManager.GetActiveScene().path);

...
}

I cant even change the active scene to the newly added scene because as far as unity is concerned when the method is executed there is only 1 scene.

Is there some way i can execute the method once the import is done? Is there some event that raises....Something easier that getting the currently running Unity PID and sending that process a message from another external script...

Upvotes: 0

Views: 220

Answers (1)

user2299169
user2299169

Reputation:

What you need is the AssetPostprocessor class, instead of what you've done so far (side note: you don't need an empty scene for a static method somewhere in your project).

Most probably what you need is the OnPostprocessModel method (you can find sample code on this link as well).
As of your 'bang' method, you can do something as simple as this:

using UnityEngine;
public static class YourClass {
     public static void Bang(GameObject myGO) {
          //Do whatever you want with the GO you just imported
     }
}

You don't need a scene or anything for this, as it's a static class with a static method; you can call Bang from whatever script you want (including your implementation of AssetPostprocessor)

Hope this helps!

Upvotes: 1

Related Questions