- Home /
Disable "Performing a potentially slow search for component..."
Hey!
With the update to 5.0 adding a component on the fly produces the following warning: "Performing potentially slow search for component [Component Name]"
This happens after using what used to be "gameObject.AddComponent([Component Name as string]);"
I really need to know how to disable this warning, or an alternative to this. My main goal is to add components based on a provided string as their name.
Thanks! Nikita
Don't know why it has to be by name, but usually you should use the generic version
gameObject.AddComponent<Component>();
Answer by meat5000 · Mar 07, 2015 at 10:41 AM
Don't use the String type of AddComponent.
http://blogs.unity3d.com/2015/01/21/addcomponentstring-api-removal-in-unity-5-0/
From the docs :
AddComponent(string), when called with a variable cannot be automatically updated to the generic version
AddComponent<T>() //<-(C#) [AddComponent.<T>() (uJS)]
In such cases the API Updater will replace the call with a call to APIUpdaterRuntimeServices.AddComponent(). This method is meant to allow you to test your game in editor mode (they do a best effort to try to resolve the type at runtime) but it is not meant to be used in production, so it is an error to build a game with calls to such method). On platforms that support Type.GetType(string) you can try to use GetComponent(Type.GetType(typeName)) as a workaround.
Your answer
Follow this Question
Related Questions
Unity is working slow and laggy 0 Answers
Unity is Slow in Editing 0 Answers
Dual monitor causing FPS drops to half 1 Answer
Compilation error, Unity 5 0 Answers
Debug.Log(files in a directory) problem 0 Answers