Turns out you can also use Transform.root as an alternative to GetComponentInParent, it gets the topmost transform of an object hierarchy, or the target object if there's only one. It's probably going to be slightly more efficient than Get Component in Parent and is a good way to get a component from the root object if you know that's where it's going to be.
@lance7135 Жыл бұрын
I've found that depends on the scene structure, though. If I have a thruster manager that wants to look at the ship it belongs to, but that ship is part of a collection that is attached to a root object, assuming it is the root object would not find the specific ship that the thruster manager is looking for. It is faster, but one needs to be absolutely sure that is the object they need.
@black_squall Жыл бұрын
The way you explain this so clearly and concisely makes me think you put an incredible amount of work into these videos. Either that or you are a God damn genius. Well done.
@SonOfSofaman7 ай бұрын
This explanation of ScriptableObjects is the first one I've seen that makes any sense.
@냥만-p2e2 жыл бұрын
I subscribed your channel right after I saw this video! I really love the detailed explanations which cover many different solutions with notes and alternatives.
@charsaurus2 жыл бұрын
Amazing video, I was searching today for a solution to this problem and was surprised at the little amount of views your video had only to realize that this was uploaded today! Excellently done and thank you for explaining everything in a manner that was easy to understand. Subscribed!
@GameDevBeginner2 жыл бұрын
Thank you!
@Ironlionm4n2 жыл бұрын
Literally my new favorite Unity developer source on KZbin
@HalTime Жыл бұрын
So much information packed into just one video! I learned so much! I'm excited to check out more of your videos :)
@GameDevBeginner Жыл бұрын
There will definitely be more. I'm just slow at making them!
@Arquivo_Tech Жыл бұрын
This is the best Unity channel on youtube
@GameDevBeginner Жыл бұрын
Thank you so much!
@arkelsean7336 Жыл бұрын
Thanks for the tutorial, I'm doing a project for university in AR and this really helped me, it's my first with unity ... Thanks a lot again !!
@mortum26142 жыл бұрын
I use two approaches to managing variables: 1. A data script where I push all my major variables to (i.e. cash, progress, etc.). This is done via a Singleton from a controller script (i.e. "Controller.instance.data.playerLevel++;") 2. Using Game Managers to manage a set of game objects along with their respective variables (level, cost, etc). I'm only about 6 months into learning Game Dev so going to Exploring incorporating Scriptable Objects a bit more after this video.
@drn18502 жыл бұрын
I appreciate the effort you put into your videos man, keep it up!!
@GameDevBeginner2 жыл бұрын
Thanks so much!
@Tetribution2 жыл бұрын
You are so amazing at explaining.. please don't stop!
@GameDevBeginner2 жыл бұрын
Thank you!
@brianwilson749711 ай бұрын
This was such an ideal video to watch for me where I'm at. Awesome work, thanks for this.
@mrepi0334 Жыл бұрын
Thank you. I was to dumb to write public in front of the reference to the class. Thank you thank you thanks you. Keep up the good work you got yourself a new subscriber. :)
@sipsopgamera7624 Жыл бұрын
Thank you so much. This video solved the problem that I was stuck on for days in a few minutes. You got yourself a new subcriber.
@randomworkshiet63302 жыл бұрын
Hey just wanna say ur video is amazing and im so glad i somehow stumbled upon ur blog. This helped me ALOT when i needed it the most.
@GameDevBeginner2 жыл бұрын
Glad I could help!
@creepermods4641 Жыл бұрын
Yo! You saved my day by making the- -the private variable to public instead. That's why my script says error haha.
@Ferundal Жыл бұрын
One of the best videos i ever saw!
@Oscorky Жыл бұрын
You could also use a design pattern such as Observer Pattern to send events between objects that way not everything is coupled together.
@GameDevBeginner Жыл бұрын
Absolutely! kzbin.info/www/bejne/gGGUq2R8YsmoY6c
@alexleonardkrea2 жыл бұрын
Fantastic Video!
@GameDevBeginner2 жыл бұрын
Thank you!
@nobodycares957910 ай бұрын
This helped my coding block!!! THANK YOU SO MUCH!
@HumbertoOriginal Жыл бұрын
Thank you, your video was the only one that worked for me
@Chocoletter Жыл бұрын
bro you are fucking amzing i was stuck on this for 3 days.
@GameDevBeginner Жыл бұрын
Happy I could help!
@MRJakeyBro Жыл бұрын
before i noticed the get component part later on in the video i had to go into the unity documentaiton to find stuff but i still got it working that way
@Ingy-d7t Жыл бұрын
Man, you are awesome! Please, go on!
@teimurlu Жыл бұрын
This was quite helpful. Thanks!
@mannig.faltigkeit23412 жыл бұрын
Thanks a lot! Good talk about clean code, too.
@yasser_gg227610 ай бұрын
all whaaat i can said is thaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaank youuuuuuuuuuuuuuuuuuuuuuuuuuuu 🥰
@whiteline4157 Жыл бұрын
super cool stuff. i have been doing it wrong all this time
@colinkeith353317 күн бұрын
it said type or namespace player (the thing i'm trying to get a bool from) could not be found and while i try to set an assembly reference because of the error it wont show up
@andrewsgates4040 Жыл бұрын
thank you for the video please I see a lot of declaring variables using data types Please what are these examples of variables below. what is this variables called public Vector3 forward; public Transform parent; public Quaternion rotation;
@carlgranstrom68272 жыл бұрын
I really like the scriptable objects approach, but it doesn't work well for multiplayer games where I don't know the amount of players I will spawn beforehand. I am using SOs for global event channels though(where I process combat events). For multiplayer I'm sticking with the "search once"-approach, although I could of course set up a sort of "playerjoined"-channel where player scripts "register" themselves by invoking an event with a reference to itself and then gets called back with events to rig them up to existing objects that it will need to communicate with. But I havn't thought that one through and I'm not sure I'll go there, I'm also quite new at Unity, and networking complicates things immensely.
@777paradoxable Жыл бұрын
What about dependency injection? In my experience, this is the best way to distribute logic and avoid unnecessary dependencies. Isn't the pattern common in Unity?
@Nirioonossian Жыл бұрын
How to change variable value in the original script from the script that's referencing it? I want to change the starting position of a line renderer on the fly via collision detection and I've been failing for days.
@ssshammi10 ай бұрын
Hi i couldent reference StarterAssets or Cinemachine in another script to get serialize object of that type. How do i do that ?
@lukedittydooda2157 Жыл бұрын
perfect, thanks!
@DannyBoy443 Жыл бұрын
You give great explnations and I love your videos. But do you have a basic C#/Unity course? I'd love that
@GameDevBeginner Жыл бұрын
Not yet, but if you / others would want that then I'll make one.
@pigtech18722 жыл бұрын
Hey mate. What theme do you happen to be using? Love the colors.
@GameDevBeginner2 жыл бұрын
I think it's Gruvbox
@pigtech18722 жыл бұрын
@@GameDevBeginner Appreciate it. Solid theme
@watercat12482 жыл бұрын
I have a question it's possible to add script or Chenge the component in a instead game object ?
@JotaaPlays2 жыл бұрын
I cant drag the script to the other, it doesnt let me, i did exactly what you did...
@FP-ih1lu5 ай бұрын
Try dragging the GameObject that the script is attached to
@JotaaPlays5 ай бұрын
@@FP-ih1lu thanks man, since last year I have learned a lot and did it like 100 times xD
@FP-ih1lu5 ай бұрын
@@JotaaPlays I figured you didn’t need this anymore but just thought I’d reply in case someone else saw lol
@humanbeing0000ZZZ2 жыл бұрын
really good
@zak-ks7ee Жыл бұрын
Could i ask I if scriptable objects work across different scenes as well? If your player character need certain variables across many different levels, especially some that your player character game object may not be holding. Would scriptable objects be a good idea for carrying variables to other levels?
@GameDevBeginner Жыл бұрын
Yes they would. So long as it's not a reference to a game object or a component that gets destroyed, scriptable objects carry their data between scenes.
@zak-ks7ee Жыл бұрын
@@GameDevBeginner thank you so much!
@MyPing02 жыл бұрын
What a well made video! It should also be noted that static variables do not get displayed in Unity's insepctor, so Singletons are a great way to work around that. I use Singletons and Public variables way for often than Find methods. GetComponent is kind of unavoidable and very useful too! Also, thanks for including Scriptable Objects in this video, they are really hard to understand for me, at least their use cases. But when you explained the similarity between Audio Sources and Audio Clips, it made sense! Great in depth explanations as always :)
@GameDevBeginner2 жыл бұрын
Good point about statics! Thanks for adding that.
@the_allay_48465 ай бұрын
dude all i wanted was to access one varaible from a diffrent script and it doesnt tell me
@fluorescente2 жыл бұрын
I tried the static variable approach exactly like in your example, but it didn't work. It just says the name does not exist in current context
@GameDevBeginner2 жыл бұрын
If you don't mind giving me more information, get in touch at gamedevbeginner.com/contact/ and I can take a look for you.
@omarkraidie Жыл бұрын
I have a public variable X in a script file attached to a game object. This game objects has nested game objects that needs to access the same variable how can I achieve this please help how is this so hard? :D
@GameDevBeginner Жыл бұрын
So I've actually got a video in the works that might help you with this but, for now, if your variable x is on your root object, other scripts can use GetComponent on transform.root, i.e. they don't have to search up through the hierarchy.
@jarrettonions3392 Жыл бұрын
You should set the background of your profile pic to the same yellow, even if you change the ; to grey or black. It would stand out more. I like that its an info i and a coding ;
@GameDevBeginner Жыл бұрын
Thanks! I might try that
@nightmarevstplugin39442 жыл бұрын
Thanks
@eren89432 жыл бұрын
so what is the right way ?
@MRJakeyBro Жыл бұрын
i then used trial and error to change a floats value in it
@Lemon-dh4fz4 ай бұрын
DI! DI! And only DI!!!
@pedropc58242 жыл бұрын
Your blog and channel are very helpful. I've never heard anything about "otherObject.GetComponent". Thanks!!!