I am developing a 2D game which includes different levels. At first I created the prefabs of the objects (enemies and other stuff), which I needed the most and I designed all of my levels by simply using the instances of those prefabs.
But at some point I lost the connection of all those instances of prefabs with the main prefab in the 'PREFAB' folder and now all of those instances are acting as normal gameobjects. Is there any way to make this connection relive? Because now I need to add some extra functionality into my game but as there is no connection of the gameobjects with the prefab, I just can't update the game by just updating the prefab.
First you can go to a Prefab and try to click Apply in the Inspector.
If it is not there at all than it really lost the connection.
In this case you can simply drag the same Object from your Scene onto the prefab in your Project View => The result should be that Unity replaces the existing "old" prefab with the current version you dropped on it and links them again.
However unfortunately this will not update all other objects in your Scene that also where once connected to that prefab so if you don't have any previous version of your project (e.g. using Git as suggested) I'm sorry you'll have to rebuild them using the prefab again.
The cause for that can be multible ones but maybe it is related to this question and there are just some scripts missing you removed / renamed lately.
Related
I'm making an online game with Photon in unity, everything is going well, but at the last moment I faced an unexpected problem.
I have a prefab object (tank) and I throw other prefab objects into this object, but it doesn't work, but it works when I put my object (tank) in the hierarchy as prefab and throw my other objects into my object (tank) as they are not prefabs.
For example, I want to make my game a mobile platform game, so I downloaded and added a joystick from unity asset store to my game.
If I assign this joystick to the movement script of my tank with the prefabs state, it does not work, but if I assign it to the movement script of my tank from the hierarchy part, it works.
What do you think is the reason for this, any ideas?
Edit, Instead of matching prefab objects from the inspector, joystick = GameObject.Find("Floating Joystick").GetComponent<FloatingJoystick>();` I matched it with my script file and it worked as I don't know why, but only the joystick in the hierarchy section worked, my fire button and camera tracking codes did not work. I think the reason is the connection I made with Photon, when connecting to photon, it is connected as server>loby>room, so the Start method works once until connecting to the room and it cannot find the specified object in the active scene. I have no idea how to solve this
sorry, my english is still bad so i use translate.
I think what you're saying is that you're assigning other prefabs to object slots in a script attached to your tank prefab.
If you do this when you're in prefab edit mode, then all your references to other prefabs are null when you instantiate the tank.
If you instantiate the tank in Edit mode, instantiate some other prefabs, and then make your assignments, then it works.
This is my understanding of your situation, at least. If this is right, the issue you're having with editing the prefab is that other objects are also prefabs, they're not instantiated.
You should be able to fix this by dragging the other prefabs onto your tank prefab, to instantiate them in the tank prefab, then drag those instantiated prefabs into your script slots.
As with basically everything in programming there are many other ways you can solve this, too, but this sounds the most like what you're looking for.
I'm new to ARCore and followed this article: https://haptic.al/arcore-101-fa6f93d4c003 to add a model with animation and see it with my phone camera.
I switched the model from the article (kitty) with a ball that I downloaded from Unity assets store, I just replaced the previous prefab object with the new one from the ball package that I imported.
Everything works fine, but now I want to download other model from the Unity store and I see that some models don't include the prefabs folder or a prefab file inside the the model package.
Is there another way to switch my current model with a new one without being use the prefab file?
Thank you.
Even if the downloaded file doesn't contain a prefab you can still create your own prefab by placing the object in the scene (.fbx, .obj files etc.) adding whatever materials you want it to have, and then dragging the name from the Hierarchy panel into the Project panel. The name in the hierarchy panel should turn blue if you've made a prefab successfully.
Note: you don't need a prefab to put something in the scene, a prefab represents an object that has a particular state saved instead of the defaults (transform rotation, materials, colliders, etc.). If you add things to an object and save that object as a prefab then whenever you place that prefab into the scene it will have those components still attached.
i have a problem when try to apply changes.
I have a GameObject in the hierarchy, i put other GO in a custom script and push apply button. All has saved, but 2 game object can't apply canges.
Thanks in advance.
If you add new objects to the transform hierarchy, those new objects can't reference the prefab because they don't know they're part of the prefab. You can tell this because in the screen hierarchy list the prefab items are blue and the rest are not. You have to save the changes from an object that is part of the prefab first or redefine the prefab by dragging the parent object onto the prefab on the project list. Because a direct save was possible, it will overwrite.
The same is still essentially true for removing objects from the prefab hierarchy, except Unity knows that this is a breaking change (because it wouldn't be mappable to the prefab anymore) and informs you that doing so well remove ALL of the objects from the prefab upward reference and you can only save the changes by redefining the prefab by dragging it from scene to project (and possibly receive another warning about the objects being different: are you sure you want to overwrite?).
Likely those Text and Transform objects are found outside of the prefab. Prefabs can't reference external objects, since there's no guarantee they'll be available for every instantiation of the prefab.
The steps I have perform:
Added an Fbx to Unity Project
FBX added to scene hierarchy
Make the Prefab of the FBX
Some assignment to prefab
Everything is working fine. I did assignment to prefab NOT FBX. Now the problem is when I importing the updated FBX, my scene object didn't updated as it links with prefab not With updated FBX. The connection of my hierarchy game object is now with prefab not with FBX. So, if I replace the FBX then, the hierarchy game object will not be update as it links with prefab not directly with updated FBX.
Is this possible to update my prefab with latest FBX** so I didn't assign again and again to my script.
OR
Any else solution.?
I guess this is the really general question which frequently face by Unity Developers. Please help.
Simplest solution that I've found for this problem is to bypass Unity's asset import system, and directly overwrite the FBX asset in your project's assets directory (eg. Copy/pasting through Windows Explorer).
Note that this will probably not work if your model has a rig/skeleton applied, and you've changed them/their relationship with the model in some way since the last version.
In those cases, I would advise just re-importing the model and setting up your prefabs again, or you'll start encountering some very peculiar behaviours. (Note that only changing animations/keyframes on a model has never created this problem for me, so in those cases you can stick to my original suggestion. Naturally you might have to change the frame ranges over which your animations are defined, though.)
Hope this helps! This is a bit of a workaround, but it has worked well for my workflow when I just want to quickly update and test assets.
In Unity3d I found the feature of saving GameObjects through dragging them from the Hierarchy into the Assets Folder. I'm using this to test stuff in a different scene.
Strangely, I it doesn't work with this one properly:
after readding it, all meshes are missing:
Do you know how to fix this?
Is there a possibility to move gameObjects, maybe through code, from one scene to another one(in editor)?
It is possible to move GameObject from one scene to another by using DontDestroyOnLoad, if you need to do so in runtime.