Комментарии:
Loving this method. I usually have a UIManager, GameManager etc where I drag assets and have the logic but from now on I will make "UIAssets" etc. to make it cleaner and easier to find where I have stored references. 😊
ОтветитьDoes this work in builds?
ОтветитьHi CM, How do I get Code Monkey Heat for reference?
Ответитьwhy is that so overcomplicated lol
ОтветитьI tired adding the Game assets script to the prefab and it just keeps telling me the script class can not be found do I need to add the game logic script as well?
ОтветитьI know this video was made a while ago but could someone explain the purpose of doing this? Like what problem it solves?
ОтветитьHi! I am not sure if you still checks comments in older videos, but I am not able get the GameAsset prefab to show in the hierarchy. I do not also get an error or anything which makes me think I am not using the GameLogic script correctly? Am I supposed to call it somewhere? I have watched the video over and over again and everything else seems to be in right places. Thanks!
ОтветитьHi,I got a null reference: NullReferenceException: Object reference not set to an instance of an object
ChatBubble.Setup (ChatBubble+IconType iconType, System.String text) (at Assets/Script/ChatBubble.cs:48)
ChatBubble.Create (UnityEngine.Transform parent, UnityEngine.Vector3 localPosition, ChatBubble+IconType iconType, System.String text) (at Assets/Script/ChatBubble.cs:15)
NpcInteractable.Interact () (at Assets/Script/NpcInteractable.cs:12)
PlayerInteract.Update () (at Assets/Script/PlayerInteract.cs:19)
You completely saved my life. I have to reference my textures in code because Texture.mipMapBias is only accessible that way, and I didn't want to wreck and clutter my project structure putting all my textures in nested Resources folder. I spent the last half day reading docs, forums and Q/As and none of them mentioned you can just have an object in the Resources folder and reference that.
Ответитьhey CM! this is an awesome video to help segue into writing more efficient coding~ i just wanted to ask, you've taught us on how to instantiate/create the asset but is there a way of deactivating it as well? let's say i don't want the asset to show up after i'm out of range within something? would really appreciate your help! cheers <3
ОтветитьThis the best thing I could Learn
ОтветитьHey! Great Video btw.
I havent a Class named UtilsClass ... what is this? ^^
Question: When building to a live build, does Unity forget to bring the resource folder in?
ОтветитьGet rid of those dangles homie those are old time and this is a typed language that has full scoping.
ОтветитьHmmm, Doesn't work for me.
The prefabs are empty in the instantiated Game Assets (Clone), even after downloading your project files.
"The variable pfDamagePopup of GameAssets has not been assigned." (But they have been.)
Could this be related to project settings?
great video! this helped me out a TON! i like your method a lot more than the standard method.
ОтветитьThank you!
ОтветитьCM sorry for so many Questions 😓😓 But can you please answer this last on this topic. The Question is why didn't you used a Method for reference instead of Property ???
ОтветитьHey CM awesome video , can you explain more about Resources folder ?? about how it is being used and the best practice to use them ? ??
ОтветитьIsn't this method of instantiating inefficient because unity always has to search the whole Resources folder for every instantiation? (ofc only if you have multiple things there, which I have since i'm using Photon)
ОтветитьCM why do you use Underscore before variable i ??? By the way awesome workflow method.
ОтветитьFor anyone who is getting the "The Object you want to instantiate is null" - Make sure you don't skip the step where he puts the "GameAssets" prefab into the "Resources" folder. That is vital! Hope that saves you a bit of time!
Love this tutorial btw - super helpful!!!
Thank you for this, this has helped me decrease the amounts of times I have had to input UI sounds.
ОтветитьHey Code Monkey! I know it's a bit late and you probably wouldn't respond after 3 years of publishing this video, but I'm getting the following error:
ArgumentException: The Object you want to instantiate is null.
UnityEngine.Object.Instantiate (UnityEngine.Object original)
I checked a couple of times and I think I did everything just as you did it, any clue of what could be happening??
I'm getting: 'Resources' does not contain a definition for 'Load'. Help, please. I'm trying to use this to go along with another of your tutorials to fire projectiles from a tower. Could it have to do with using a newer version of unity? I made the Resources folder and added a new prefab to it and all that by commenting out the if statement long enough for the scripts to compile, but when I uncomment the if, the error still comes back.
UPDATE: I solved it. I had another script named Resources that I just had to rename.
i tried this out and its pretty great for sure. some tips i would add is that you can put headers in the script with [Header("Prefabs")] just to organize all the assets in the editor. i also open a second inspector screen and just lock it to this game objects so i can always flick over to it and add the asset as im making them.
ОтветитьOMG just the exact thing i wanted to know! Also, you think this could run for a ScriptableObject?
ОтветитьDo you think it's bad for performance or I'm overthinking it, because imagine a lot of assets there and I think it loads all the assets even if they all are used in that scene or not.
ОтветитьAwesome Tutorial! This saves me so much time and code mess. I have a question however, I tried to put some GameObject prefab in this script, but when I tried instantiating it from another script, it gives me "The Object you want to instantiate is null" - it seems like it has something to do with the static nature of it, since I tried putting this same prefab on another (non-static) object and it got instantiated properly. Any thought on this?
ОтветитьHey CodeMonkey, I've been using this technique for a while now, and it's super convenient. I always feel a bit uncomfortable making all those public fields, though. Thoughts on this? I know that in general, it's best practice to make fields private if possible, but obviously the whole idea here is to access these fields from anywhere, so...I'm not sure what the best solution is.
ОтветитьI didn't realise instantiating the prefab was so simple. I was scratching around looking for examples and ended up using AssetDatabase.LoadAssetAtPath ... PrefabUtility.InstantiatePrefab. This method is much simpler, thank you.
ОтветитьI am trying to use this with a Common Mono Library I created that contains common used functions such as a "Destroy After Time" coroutine. However I am encountering an error, "Coroutine couldn't be started because the game object is inactive" after calling it through GameAssets.i. The function does not appear to be at fault as I tested it with the class housing the script directly on the object I wanted to destroy and it worked fine. It appears to be due to how its being used within the GameAssets prefab.
Do you have any recommendations on how to go about this?
"the object you want to instantiate is null" error occurs
Ответитьcan'r add scriptr component 'GameAssets' because the script class cannot be found make sure that there are no compile errors and that the file name and class name match.
i have this error but everything i wrote into the script is exactly like yours,the same for folders or folders and fail path, which is the problem? i'm using a unity 2020.1.12f1
I cracked open my head as why it didn't work, it kept giving a null error. In the end I created a folder named Resources to put the GameAssets object in and suddenly it worked. Previously I had put it in a folder which I named Prefabs, . I don't understand why the folder name made all the difference. If by any chance you see this, could you explain to me why the folder had to be specifically named Resources? Does the Resources class require a folder specifically named Resources? I'm a bit new.
Ответитьhey thanks for your tutorials, it's very helpful then . what about " Using Unity engine Codemonkey " in liberary ? how can i get it ?
ОтветитьI hate you! Now I will have to refactor all my code! this is going to make my life so much easier! thanks!
ОтветитьI don't understand. How did anything get called without a start or update function?
ОтветитьHow do I reference a textMeshPro pannel?
ОтветитьO.O, amazing!
ОтветитьHello! I have a question. Can I use this method with any project without using the CodeMonkey.Utils? At the beggining of the script?Thx :)
ОтветитьWe apologize for my perseverance in asking you many questions about your various tutorials. I find your approach to scripting very interesting, instead of using Mecanim or Animation from Unity sprites. But I would like to understand well the mechanism that you have implemented to load animations via code or data. If you prefer I can give you my email, so we don't occupy this channel, with my questions for clarification.
ОтветитьYou created a prefab named GameAssets with which you associated the GameAssets.cs script. Now the prefab where did you put it in the scene ?
ОтветитьIs this like a more efficient way of object pooling or more like the same but just a lot cleaner? Or am i just completely wrong lol?
ОтветитьHey man I'm getting a stack overflow error when I try to use this GameAssets script in my game. Any ideas? Basically I set a reference to a projectile that my character is firing on the GameAssets script / prefab and then just instantiate it on the PlayerController script when I fire.
ОтветитьIs this like a singleton?
ОтветитьIf you mentioned how to dispatch GameLogic.Init(), it makes this video better.
ОтветитьI didn't get, the static method Init from gameassets, where it's called?
Ответить