Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Java
AssetDatabase.Refresh();
		AssetDatabase.ImportAsset( path, ImportAssetOptions.ForceSynchronousImport );

		var gameObj = target.gameObject;
		var script = AssetDatabase.LoadAssetAtPath( path.MakeRelativePath(), typeof( MonoScript ) ) as MonoScript;
		InternalEditorUtility.AddScriptComponentUnchecked( gameObj, script );

		#region Delayed execution

		// Declared with null value to eliminate "uninitialized variable" 
		// compiler error in lambda below.
		EditorApplication.CallbackFunction callback = null;


What I have tried:

I am not change anything in this code.
Posted
Updated 4-Feb-18 1:13am
v5

1 solution

AddScriptComponentUnchecked is in the InternalEditorUtility class because it's not intended for public use so it can change anytime without notice[^], and it looks like you're using a Unity version that's too new to use this method.

You should check if there's a way using public methods to do what you want. If you think there isn't, then you can use reflection to access the private AddScriptComponentUncheckedUndoable method on InternalEditorUtility (but if you can avoid that, then do avoid it). For that, see WolfieMario's review to the 'Create Script Dialog' Unity asset[^] and adjust that to your code.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900