Hi i'm downloading a file in to unity but i need to move the file in to a folder. How can i do this in C#?
Do you mean how to put the game object as a child of another? (That's what it looks like from your screenshot)
If so, you can accomplish that by setting your game-object's transform's parent to the transform of the "folder" you want to put it into.
Something like:
teapot.transform.SetParent(NEWTest.transform);
http://docs.unity3d.com/ScriptReference/Transform.SetParent.html has more information.
Related
I have created a custom inspector using the UI Toolkit. The way I initialize the UI Document is as follows:
public VisualTreeAsset uXML;
This uXML is assigned through the inspector. Then in CreateInspectorGUI:
root = new VisualElement();
if (uXML == null)
{
Debug.Log("UI Document is " + documentName + " null");
return root;
}
uXML.CloneTree(root);
The root is the main root of the UI document (I am using UI Toolkit).
The problem is that when I enter play mode, the Inspectors disappears as shown:
I’m going to assume that you used a “Default Reference” for your editor script. Unfortunately, the default reference is only deserialised when you're in "Edit" mode. As soon as you go to "Play" mode, the reference is null.
The general way to get around the issue is to search for your asset when you create the inspector window:AssetDatabase.LoadAssetAtPath<VisualTreeAsset>("Assets/PathToYourFiles/YourFile.uxml")
Unfortunately, if you move your files somewhere else, you need to go in an update the string file location. Because it's a string path, there's no reference to follow the file if you move or rename the file. It's not clean, but it's easy, and gives you your inspector when in Play mode.
I did a quick search on the issue. Looking at this document, it seems Unity also suggest using Addressables or the Resources folder.
Because you don't really want the assets to follow you into a final build, I prefer placing them into an Editor folder, and just making sure I'm careful when moving or renaming the files. In one project, I made an automated process that "found" the file for me. It involved using a ScriptableObject and Assembly Reloads but I'm still in two minds whether the effort was worth it.
I'm using Unity 2020.1.1f1, when I try to add a Component to a GameObject, the component that I search for does not show up for me to add it? The component I have is located in a sub folder of Assets. Should I have imported it elsewhere? I have also restarted Unity to see if it would refresh.
Short answer: It should derives from MonoBehaviour
Looks like there is a thread on this already, I'll close this with the link: Can't add script component because the script class cannot be found?
I'm new to unity. I want to try this tutorial but I failed.
I created a GameObject - UI - Button, and tried to add script to Canvas. But I got this error. Any help would be appreciated.
OpenFolderPanel is an Editor script which lets people to make some customized function for Unity Efitor.
If you want to click button to show file dialog in your game, you can try StandaloneFileBrowser
Alright, I know your mistake. When you create a c# script, do as follows (if you want to attach it to a gameobject).
1) Select the gameobject in the heirarchy.
2) Click add component in the inspector window.
3) Type in the name of your new script, and Unity will generate a basic script derived from MonoBehaviour automatically.
BTW, game objects have monobehaviour derived scripts on them (in singleplayer). The script you are using is derived from EditorWindow, not MonoBehaviour. Personally, I have not used a custom editor, but I think the script you are using should work automatically without having to attach it to a gameobject.
I want to use in a custom component a background image, but I can't find how to use it from the scss file.
I think there must be a way to define another directory for my images. I don't want to mess up files that correspond to this specific component sending them to 'www' directory.
Is there a way?
I give you an example of what i want:
Let's say I have a component defined in 'src/app/shared/components/my-custom-component'. Inside this directory I have a '/image' directory with all the images I want to use in this component. Then, in the 'my-custom-component.scss' I want to use this images using backgroun-image...
Is it possible to do this?
I have a model of a person in my project and I found another .obj file online. I imported it into the project and changed the name of that to the name of the original object. I also changed the name of the new material to the name of the old material. Then I deleted the original file and the object does not show up on the scene anymore. Any help would be greatly appreciated! P.s. I am using unity version 5.3.4.
Unity does not reference elements by their names. If you delete the referenced object then reference will be lost, unity will not lookup for another object with same name.
So, to display object_2 in place of object_1 you have to manually change the reference from object_1 to object_2 in the inspector. Or if object_1 is directly placed in the scene then simply delete the object_1 from scene and drag & drop object_2 from project to scene hierarchy.
You need to locate your model in the Project tab and drag it to your Hierarchy tab