- Home /
How to detect if unity build scene for target platform or editor player
I am using PostProcessScene attribute to hook script build
I want to know if it is building for playing just in editor or it is building for running in target platform
What class or method I could use to specify this information?
EditorUserBuildSettings.activeBuildTarget
This will give you the platform you are building. If you want to run certain script on build platform
switch(EditorUserBuildSettings.activeBuildTarget)
{
case BuildTarget.Android:
//your code
return "Android";
case BuildTarget.iOS:
//your code
return "iOS";
}
It could give current platform targeting build but it cannot tell that it just running in editor playmode or actually building to device
BuildPipeline.isBuildingPlayer is what I am looking for.
Answer by ASDUnity · Jan 12, 2016 at 04:56 PM
Try using BuildPipeline.isBuildingPlayer, http://docs.unity3d.com/ScriptReference/BuildPipeline-isBuildingPlayer.html
Thanks! BuildPipeline.isBuildingPlayer is what I am looking for.
Answer by MadDevil · Sep 29, 2015 at 09:11 AM
@Thaina, you can use the pragma like below.
"#if UNITY_EDITOR print("Hello"); #endif "
The code written inside the above pragma will only execute in editor not on the targeted platform.
It cannot tell that it is currently build to target platform or just run in editor sceneview. Both are define UNITY_EDITOR when the code is in editor script folder
Your answer
Follow this Question
Related Questions
Available Platforms Detection 1 Answer
Platform switch to trigger a function 0 Answers
Show object for a specific platform only. 3 Answers
Using a custom icon for game objects with Gizmos.DrawIcon 1 Answer