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.
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.
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.
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!
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.
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.
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. :)
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
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;
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
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?
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.
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.
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?
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.
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
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.
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 :)
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 ;
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.
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.
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.
This explanation of ScriptableObjects is the first one I've seen that makes any sense.
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!
Thank you!
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.
Literally my new favorite Unity developer source on RUclips
So much information packed into just one video! I learned so much! I'm excited to check out more of your videos :)
There will definitely be more. I'm just slow at making them!
This is the best Unity channel on youtube
Thank you so much!
You are so amazing at explaining.. please don't stop!
Thank you!
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 !!
This was such an ideal video to watch for me where I'm at. Awesome work, thanks for this.
I appreciate the effort you put into your videos man, keep it up!!
Thanks so much!
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.
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.
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. :)
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.
Glad I could help!
One of the best videos i ever saw!
This helped my coding block!!! THANK YOU SO MUCH!
Fantastic Video!
Thank you!
Yo! You saved my day by making the-
-the private variable to public instead. That's why my script says error haha.
Thank you, your video was the only one that worked for me
Man, you are awesome! Please, go on!
This was quite helpful. Thanks!
You could also use a design pattern such as Observer Pattern to send events between objects that way not everything is coupled together.
Absolutely! ruclips.net/video/J01z1F-du-E/видео.html
Thanks a lot! Good talk about clean code, too.
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
super cool stuff. i have been doing it wrong all this time
bro you are fucking amzing i was stuck on this for 3 days.
Happy I could help!
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;
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
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?
perfect, thanks!
all whaaat i can said is thaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaank youuuuuuuuuuuuuuuuuuuuuuuuuuuu 🥰
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.
Hi i couldent reference StarterAssets or Cinemachine in another script to get serialize object of that type. How do i do that ?
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.
really good
You give great explnations and I love your videos. But do you have a basic C#/Unity course? I'd love that
Not yet, but if you / others would want that then I'll make one.
I have a question it's possible to add script or Chenge the component in a instead game object ?
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?
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.
@@GameDevBeginner thank you so much!
Hey mate. What theme do you happen to be using? Love the colors.
I think it's Gruvbox
@@GameDevBeginner Appreciate it. Solid theme
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
If you don't mind giving me more information, get in touch at gamedevbeginner.com/contact/ and I can take a look for you.
dude all i wanted was to access one varaible from a diffrent script and it doesnt tell me
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
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.
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 :)
Good point about statics! Thanks for adding that.
Thanks
so what is the right way ?
I cant drag the script to the other, it doesnt let me, i did exactly what you did...
Try dragging the GameObject that the script is attached to
@@FP-ih1lu thanks man, since last year I have learned a lot and did it like 100 times xD
@@JotaaPlays I figured you didn’t need this anymore but just thought I’d reply in case someone else saw lol
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 ;
Thanks! I might try that
i then used trial and error to change a floats value in it
DI! DI! And only DI!!!
Your blog and channel are very helpful. I've never heard anything about "otherObject.GetComponent". Thanks!!!