#💻┃code-beginner
1 messages · Page 502 of 1
What system are you even using?
currently its just set up to make the gameObject to setactive whenever canInteract becomes true, which becomes true if the raycast hits a layermask called "pickupLayer"
What is the setactive gameobject? Does it have a collider or something?
it was working fine before, and the script was left unchanged because of that. but now i get random snapping of the camera whenever i hover over the pickupLayer
yes
the problem isnt that its not registering it, because it is. its that for some reason something is causing the camera to suddenly snap away.
ill just figure it out later ig
Does your player get pushed away by that collider for some reason?
Yeh, depending on where you stand, it can have different effects. Can you just disable the collider for test purposes?
im going to turn off gravity then cuz its gonna fly through the floor
well its not causing any problems now, but the raycast isnt hitting anything
i shall try something else
You should check the physics collision matrix and place your items on another layer than your player
how do i delete the wolken Script component
https://gyazo.com/8f206b85c6206f6a83609417ab9c75a7 there is no delete ooption lol
Try the remove component?
Hey so I am still super early in learning, but I have two questions. Firstly, is unity learn going to be enough for basically anything? Or should I look up/use third party tutorials as well? Secondly, how will I know that "I am ready" to make something bigger? Obviously Ill start with smaller projects for practice and experience but I'd like to move onto something bigger when I have enough knowledge.
i want to create a system where when the player dies the scene instantly restarts however would the engine take longer restarting the scene than just resetting everything else
Unity learn might not be enough for "anything". Nothing will be enough for "anything" actually. Unity learn would help you with the basics. Beyond that you're on your own. Learn and research whatever you need for your project instead of everything.
Also, you would never know when you're ready. You just try it and see yourself if your goal was too ambitious. That is, after you got the basics down of course.
Fair point, I mostly meant anything as in Ill know my way around unity mostly.
I dont think my goals are THAT ambitious honestly so once I get over most of the basics I feel like I wont get stuck much
Assuming you're reloading the scene, that would obviously take more time than just resetting some variables. Reloading implies unloading objects and resources from the memory, loading them again and initializing everything.
hmm ok well is there a good way of ressetting everything other than resetting all the transforms and bools of everything
How different is unity 6 from the current LTS version? Any major differences that I should consider while learning?
There isn't. That's pretty much what you'd need to do. You might write some code that makes it easier though. For example have a resetter component and/or have your scripts implement a sort of resetter interface.
That being said, while scene reloading would take more time for sure, perhaps it's a compromise you're ready to take. That's a design decision.
There are plenty, though most of them are probably new features. Better start off with lts.
no i just tried resetting the scene takes like 1-2 seconds im gonna reset everything lol
!code
📃 Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
Is there anything in my code that could be preventing me from interacting with the game? I start the game and I can't interact with it at all:
https://hastebin.com/share/onexumusoy.csharp
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
as in keyboard presses or wdym cant interact
What kind of interactions are you expecting?
To click a button and enter text into an input
check if you have an event system in your scene
Yeah make sure there's an event system
and the appropriate raycasters/input module
if i have a script on a prefab i can just Instantiate that?
or do i have to do GameObject?
im getting a "the object you want to instantiate is null" error
are you asking if you can instantiate a script?
i want to instantiate the game object but as of type as the script, so i dont have to use GetComponent on it
or does this only work with rigidbodies and stuff?
you can just create a new variable and do = Instantiate(prefab).GetComponent<T>();
yeah i know, but with rigidbodies you can just instantiate that directly i think so i thought the same applies to a normal script but i guess not
oh i see, but no i dont think this works with anything other than rb
yeah, works fine as a GameObject though so ill have to use GetComponent
yes that applies to any component on your GO. not limited to rigidbodies in the slightest
https://docs.unity3d.com/ScriptReference/Object.Instantiate.html
the docs for instantiate are clear, they take any UnityObject. Theres no limitations on this being a GameObject or Rigidbody
Take a look at the 3rd/4th example too.
why am I not getting Auto Complete?
is your !ide setup?
If your IDE is not autocompleting code
or underlining errors, please configure it.
Select one:
•
Visual Studio (Installed via Unity Hub)
•
Visual Studio (Installed manually)
•
VS Code
•
JetBrains Rider
• :question: Other/None
so i can instantiate my own script?
would you know why it would error as null then?
or maybe its that i didnt put it in a variable and change it on that, but directly on the instantiate instead
I tried enabling this, though it didn't change anything.
I'll take al ook
im not sure what you mean by the next sentence, its just entirely likely you didnt plug it in the inspector after changing the type
I'm trying to make a camera control script to use with a joystick here: https://paste.ofcode.org/Z2S9aHRA9rihXqmcczWRfE, but when i use it it both snaps back to the default camera, and the camera clamps on the left and right as well as up and down. I assume the camera snaps back due to something with the multiplication and the joystick at position (0,0), and the clamping is due to soemthing with the Mathf.clamp method, but i'm not super familiar with it.
Also, mouse x and mouse y are bound to the correct axes in the input manager
Should I start with the unity beginner programmer or unity essentials? I’m about done with code academy’s intro to c#
I went through this for Visual studio Code and I'm fairly sure I went through all the steps. Even though I'm using VS Code is Visual Studio actually nessecary??
it automatically changed it, but just to make sure i even removed the component and added it back and manually re assigned them but it errors
as soon as i change the variable to GameObject the error is gone
but ill try it again later maybe i did something wrong
I'd recommend this if you've just covered if-statements and whatnot - some rehashing of what you've learnt but practical to Unity. If this is too much information, you may want to brush up a bit more with the basics without Unity.
https://learn.unity.com/project/beginner-gameplay-scripting
Assuming you just finished https://www.codecademy.com/learn/learn-c-sharp
Visual Studio and VSCode are both different. choose one to work with. Visual Studio is an actual IDE and easier to setup/use. VSCode is a code editor that is lightweight, and plug-in friendly for many coding languages . . .
Hiya yall! Im a starting dev and im learning c# rn, but a lil problem i have is that im struggling with writing code.
I understand each piece of the code what it does but i struggle with just writing it into a proper script, does anyone have tips to make it easier?
(Its like knowing what the pieces in a pc do but that u have no idea how to put it together into a pc)
Idk if this is the correct chat for this but if it isn't please redirect me!
I want to check if an object is in the camera view, and I've looked online and tried many solutions like OnVisible, and TestPlanesAABB with camera frustums but they dont work if the object is behind another object, or if you arent looking at the center transform of the object or in other words you are looking only at a small part of the object.
I'm going to do raycasts for the entire camera view with spacing in between them, but surely unity has an inbuilt function for this already, can anyone help point in the right direction?
OnVisible should work imho. Unless you're using occlusion culling.
And testplanesaabb should work if you provide proper bounds
I dont remember adding a second camera in the first place. why am I getting errors trying to remove it?
{
// LogicoScripto is another script I want to use a number from
public LogicoScripto scoreText;
public Text HighestScore;
// you can ignore this int for right now
public int PlayerScore;
void UpdateScore()
{
GameObject.Find("playerScore").GetComponent<LogicoScripto>();
if(playerScore )
}
}
Im trying to code a highscore and I coded this so far. But when I want to use the "playerScore" from the other script it says as an error that "The Name "playerScore" does not exists in the current context."
What am I doing wrong. I thought I could maybe use find to grab the number from the other script.
Normally you'd cache the reference then use it. For example:cs var logico = GameObject.Find... if(logico.playerScore > ...) ...
But if the two objects are in the scene, you should consider referencing from the inspector instead: cs [SerializeField] private LogicoScripto logico; ...``````cs if(logico.playerScore > ...)
where you'd drag the other game object from the scene into the inspector field of the script that wants access to that object's component.
but if I do private dosent it NOT show up in the inspector?
https://docs.unity3d.com/ScriptReference/SerializeField.html
It's serialized so it'll show up in the inspector. If other objects should be able to change this reference then you'd have the access as public.
You should probably move non coding question to #💻┃unity-talk or some other relative channel id:browse
sure
public LogicoScripto scoreText;
public int HighScoreText;
public Text HighestScore;
void UpdateScore()
{
GameObject.Find("playerScore").GetComponent<LogicoScripto>();
if(scoreText.playerScore > 0)
{
HighestScore = GameObject.Find("playerScore").ToString;
}
}
}
I now have this but it says that .ToString isnt working
because ToString is a method not a varaible
I don't think you need that find and get component method.
Methods should have ().
But how else would I get the Number from the other script?
I would like to use your first method
If you want to use find (not advise) you'd cache the component
how would I do that? 😦
public int HighScoreValue;
public Text HighestScore;
void UpdateScore()
{
var logico = GameObject.Find("playerScore").GetComponent<LogicoScripto>();
if(logico.playerScore > HighScoreValue)
{
HighestScore.text = logico.playerScore.ToString();
HighScoreValue = logico.playerScore;
}
}```
you missed the .text
I'd recommend taking a C# course if you're having issues with something so basic as saving a method return value into a variable and using that
Im trying to avoid tutorials
Dont want to end up in hell
And here's the result
Take a normal C# course, the link is in the pinned messages in this channel
well don't expect to be constantly spoonfed here
thats exactly what i did and thats the only reason i ended up in hell lmao
are you still in hell?
no ive been out for a long time, but its only because of persistence
would not recommend this method though
I strongly advise to take a C# course
But do I actually learn something if I do that?
dont I just reproduce?
if you follow along and practice then yeah
At a basic level, yes
think about the learning process for coding to be similar to math, you have to learn and practice in order to remember and understand
Those courses exist and are pinned here for a reason
You first learn how to place a single brick, then make a wall out of them
Something I also never understood was:
Dont learn Syntax, learn problemsolving.
TF am I supposed to do if I dont even know how to write specific things in the first place.
i mean, i feel like this advice is super counter intuitive because to learn coding basics, everyone already has enough problem solving skills (assuming youre not a child)
to program you need to problem solve, to code you need syntax, they are not the same thing at all
but following along with courses will teach you problem solving as well
Problem solving and syntax are two different things, but you still need both
Ohh okay
can anyone help me with this script refusing to recognise AudioListener? it just keeps erroring that the refrence needs to be an instance of an object
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AudioSettingApplier : MonoBehaviour
{
public AudioSource audioListener;
private void Awake()
{
if (audioListener == null)
{
audioListener = GetComponent<AudioSource>(); // Automatically assigns AudioSource from the GameObject
Debug.Log("assigned: " + audioListener);
}
}
private void Update()
{
audioListener.volume = SettingsHandler.instance.Volume;
Debug.Log(audioListener.volume*100);
}
}
The thing is, I basically took a course, but the guy then said: Figure out how to do things like animation and HighScore by yourself. Thats my situation kinda
Do you maybe have this script on more than one object in the scene?
Then don't listen to the guy, if you don't know how a tool works then how are you supposed to use it blindly? You have to either take a course or consult the docs to know how to use it. But your problem right now isn't with animation or high score, it's basic C#, so go learn that.
screenshot your console, please dont dripfeed relevant information
Yeah that's some horrible advice
For your case
Discouraging, but I guess I have to pull trough
just the camera
then SettingsHandler.instance.Volume is your problem not the AudioSource
i never set it initially thats why. thanks
That's odd, I already have the InputSystem set up with the name but I cant connect it.
Following a video tutorial for the script in question: https://hastebin.com/share/xojunusoti.csharp
Said Video Tutorial is from here: https://www.youtube.com/watch?v=q-VfsQQlji0
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
Let's build a simple mechanism to move player around the scene. We are going to use the new Input system in unity. Let's learn how to receive inputs and read them. We will learn to create an action map, input actions and bindings to achieve our mechanism.
Please do support me on patreon.
Patreon - https://patreon.com/OpenWorldEra
Feel free to ...
its PlayerInput not system
Ah, my mistake.
`obvious error
PlayerInputSystem playerInput;
...
playerInput = GetComponent<PlayerInput>();
Ahh
hello
i have a big issue going on here
whenever i instantiate a new game object
it says on the end of the name of the gameobject gameObject(Clone)
how to remove the (Clone) from the end of the gameobject
seyt the instantiated objects name property
i am setting names like this
and please type in full sentences before pressing enter
GameObject Managed = new GameObject("Managed");
sorry i will try not do it again
this will not add the (clone)
this
Instantiate(prefab);
will
is there any alternative?
sure
GameObject newObject = Instantiate(prefab);
newObject.name = prefab.name;
it is over complicating things
i hope it works
Followed everything right, though I never seen this error occur before.
you dont have the component on your object
so your GetComponent is not working. Is the component on the same game object?
You can also use https://docs.unity3d.com/ScriptReference/Component.TryGetComponent.html to include checks and log fallbacks when its failing
this is very common, expect to see it a great deal
it always boils down to the same problem, you are assuming something which is not the case
I need to watch the video again.
I advice you to read the docs about the types and methods you are using in the tutorial. Otherwise you will just follow someone telling you what to do and have a very narrow learning curve
Will do.
and this is why I hate video tutorials, they show but do not teach
Tea
I rather read several pages of a blog post tutorial then watching one tutorial again, that is not covering a specific topic just to remind
I did miss something.
yes, you forgot to add the PlayerInput component to the gameobject
hey when i do change the name and remove the clone keyword from the end
it creates another gameobject with clone written at its end
how to deal with that?
show your code
My bad, its all fixed by now.
If it created another gameobject, you are creating it via code, so you most likely copied the line to the next and tried to set the name on a new instance.
Thanks Smith
let me see
its like 5k lines of code
so i dont know what to show with it
just post the bit where you are making the gameobject
ok let me
if (!UAEFileRoot.Find("target").Find("Managed").Find(ids.ToString()))
{
GameObject Entity = new GameObject(ids.ToString());
Entity.AddComponent<TypeFieldCell>();
ContactInfo Infos = new ContactInfo();
Infos.Name = Entity.name;
Infos.Type = identifiers[54];
Entity.GetComponent<TypeFieldCell>().ConfigueHierarchyCell(Infos);
var obj = GameObject.Instantiate(Entity, UAEFileRoot.Find("target").Find("Managed"));
obj.name = Entity.name;
}
Transform GEntity = UAEFileRoot.Find("target").Find("Managed").Find(ids.ToString());```
so you are creating a new gameobject already with Entity line, then instantiate a gameobject again
new Gameobject will just be an empty gameobject in your hierarchy
also, for whoevers sake, get a better way to avoid all those Find() calls.
🥲
yea
but for some reason there are duplicates
because you are creating them
one with no clone written at the end and other with clone written at the end
this
GameObject Entity = new GameObject(ids.ToString());
create an new object and this
var obj = GameObject.Instantiate(Entity, UAEFileRoot.Find("target").Find("Managed"));
makes a duplicate of it

you mean the gameobject was in the scene already and i am just duplicating them instead of setting them as parents
then what's the instantiate for?
you dont need the instantiate, replace it with Entity.transform.SetParent

thanks for the big info
let me fix my code
better yet, completely rewrite it because it is horrible

its not easy to rewrite 5k lines
that block is though
it is being reused and modified and then reused again and again
its not a function
and, if you have a 5k line script you are definitely doing something (probably lots of somethings) very wrong indeed
nooo
it used to work
i intended to make a hierarchy like suppose you open a folder and you want to see the contents of the folder in a hierarchy like you open folders and stuff like that
previously i wrote the code when on button click the contents were shown
but now i am working on making it a complete hierarchy so in simple words i am just modifying the previously existing code
take a look at this
this is also a hierarchy but i this case of gameobjects
inside scene
ok, that should probably be less than 200 lines of code, not 5k
and opening some other file formats like rar and zips so yeah
irrelevant, it sounds like you have never heard of loops
I am not a good programmer
i turned 18 a few months ago
let me give you a tip.
Look for patterns and duplications in your code, all of those means you should be using loops and methods not copy/pasting
thanks for the advice
I have a script that derives from Button. How do I add my own code to Start() or Awake(), or is there an alternative?
which Button, there are 2
UnityEngine.UI
public class Button : UnityEngine.UI.Button
{
new void Start()
{
base.Start();
// Your code here
}
}
Don't do this
new hides the original method, and if you were to cast or match the old button, then it uses that Start method instead
Button inherits from Selectable, which inherits from UIBehaviour. This method has a virtual Start method you can override
So override, don't new
It is my understanding from the OP's question that that is exactly what he wants
@weak cedar
You add your own code by overriding
public class Button : UnityEngine.UI.Button
{
override void Start()
{
base.Start();
// Your code here
}
}
new should generally only be used if a method is not virtual, though in this case you should wonder why it's not virtual in the first place
this is what I want
I'm making a custom button with some tweening animations, and since the Button completely overrides the inspector, I can't drag and drop image references
so I need to pass references somehow
would your start method even be called by unity if you use new?
Not sure. I have no idea how this would fix their issue, hence why I suggest against it. But, this is probably my lack of understanding what the point is
it does
so why do you suggest I use override and not new?
Like I said, new hides the original method where override actually overrides it. I don't see how override would not work here
wdym by hides?
The issue is that if you were to call one of the base methods, you would not call the final new method in one of its derived types. Compared to override which overrides the method and does call it
So if Unity calls Start in a way where it does it from one of the base types, it will not call your new method
And perhaps it actually calls it from MonoBehaviour. I don't know what logic they use here
Regardless, if this happends, it would call the final method. In your case there are no overriding methods, and thus the base virtual Start method is called
But like I said, I don't know your issue well enough to see why new could possibly work better here. I haven't used Unity enough for that
override doesn't work anyway
how do i make dynamic rigid body not flip in unity 2d i want my charechter to not fall and flip
stop cross posting
ok works this way
Also, here is an example https://dotnetfiddle.net/SuZ5TL
Test your C# code online with .NET Fiddle code editor.
Notice with the first and second line, both call the final override method and not the new method
It's only when you directly use the class with the new method where it works
except Unity runs it's methods via Reflection not standard C#
Like I said, I don't know what logic they use and what is called in the end
This is just an example of the issue with new and why you should override instead
I'm not going to use any of the base classes methods. In fact, just Start()
ty for elucidating btw
You're not the one calling the methods though
using System.Collections.Generic;
using UnityEngine;
public class MovementScript : MonoBehaviour
{
static string deathTag = "DeathWay";
public GameObject player;
public float moveSpeed = 5f;
public Vector3 teleportPosition;
private Rigidbody rb;
void Start()
{
player.tag = "Player";
rb = player.GetComponent<Rigidbody>();
if (rb == null)
{
rb = player.AddComponent<Rigidbody>();
}
}
void Update()
{
float moveHorizontal = Input.GetAxis("Horizontal");
float moveVertical = Input.GetAxis("Vertical");
Vector3 movement = new Vector3(moveHorizontal, 0f, moveVertical);
rb.velocity = movement * moveSpeed;
}
void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.CompareTag("DeathTrap"))
{
player.transform.position = teleportPosition;
}
}
}
``` MissingComponentException: There is no 'CharacterController' attached to the "PlayerBase (1)" game object, but a script is trying to access it.
You probably need to add a CharacterController to the game object "PlayerBase (1)". Or your script needs to check if the component is attached before using it.
MovementScript.Update () (at Assets/Scenes/MovementScript.cs:14)
The error is telling you what to do . . .
Fair enough 😄
This error doesn't match this code to be honest. Make sure you saved your code.
you cannot create an instance of an abstract class. you can only create instances of a concrete implementation
you also don't have a CreateAssetMenu attribute on that anyway so even if it weren't abstract, you can only create an instance of it in code
in here i did override which is not instancing?
okay so then create an instance of that object using the Create menu
Hey Guys i have an weird problem i am doing the unity beginner program and i just cant watch any of the videos because they wont load even tho i have a good and stable connection to my Wifi.
Has anyone a Tip for me how to fix it?
that's not a code question. that is not really even unity related as it's an issue with your own internet connection. if you cannot watch videos due to poor internet, then find text based courses
how can I fire an event on EditorGUILayout.Toggle?
okay i am sorry i didnt knew where to ask i will i am sorry
https://docs.unity3d.com/ScriptReference/EditorGUILayout.Toggle.html read the documentation
I did.. there's nothing about an event there
there is, in the code example
id:browse to find the various subjects, and always read the topic first.
this does something every time OnGUI, not when the checkbox is clicked
you can simulate that by using a property
pretty new to C#.. this means with get/set?
yep
bool _setBtn;
bool setBtn { get { return _setBtn;}
set {
if (_setBtn != value) {
_setBtn = value;
OnToggle(value);
}
} }
i have a main folder with many subfolders. these subfolders contain many images. i want to change the filter mode of all these images to Point no filter. How do i achieve this, can i automate this? I dont want to go each folder, ctr a and change it to point no filter, when there are about a thousand folders to get through.
cool, thank you
If anyone could help me, i would appreciate it a lot. thank you all
#↕️┃editor-extensions but you need an AssetPreprocessor script
Hello I have a Serializeable and I am having an issue where I cannot drag my Text or Image component to the list i am not sure why this is happening how do I make it work?
[System.Serializable]
public class UpgradeUI
{
public Image icon;
public Text name;
public Text description;
}
your Text component is probably actually a TMP_Text, as for the Image component, make sure your variable is the right type of Image. UnityEngine.UI.Image is not the same as the UIElements.Image type (you want the former)
i made sure that i am dragging a legacy text/image component and it says type mismatch or just not allowing me to do it
then are you perhaps trying to drag scene objects into a prefab or other asset?
yes
please say that next time. prefabs cannot reference in-scene objects. you have to pass the reference at runtime when you instantiate the prefab
https://unity.huh.how/references/prefabs-referencing-components
also consider switching from the legacy text to text mesh pro, it's better is nearly every way (unless of course you like your blurry text)
i see, so how do i correctly connect the text component to my script? I wanted to display the text from my script to the UI
how can i await a method thats not async? or wait until this method is executed?
got it thanks
if a method is not async then it will complete before the next line of code runs when you call it
You cannot. If you want a delay, it needs to either be async or a coroutine
whatever is supposed to use that returnValue variable should be executed in the result callback. because this is clearly an API request which means that callback isn't executed here, it is executed whenever that API request completes
If you want something to happen after returnValue is true, instead of having this script return a value to something, just have the ExecuteCloudScript call that function instead of setting returnValue
is it possible for a raycast to be blocked by a trigger collider
yes, if the setting for it is on
is it on by default
no
oh oof mine was dont know when that happened or if its a unity 6 thing
yes
cool that fixed my issue
{
SceneManager.LoadScene("Tutorial" + player.currentScene.ToString(), LoadSceneMode.Additive);
player.playerStart = GameObject.Find("PlayerStart" + player.currentScene.ToString());
}```
is there a function to wait for unity to finish loading a scene or do i need to put this in a coroutine
you could use the async method to wait for it
also you can use the scenemanagers events https://docs.unity3d.com/ScriptReference/SceneManagement.SceneManager-sceneLoaded.html
{
Debug.Log("Loaded");
player.playerStart = GameObject.Find("PlayerStart" + player.currentScene.ToString());
}```
it doesnt call at all not even when i start the game
you need to subscribe to the event
is there a special process to using FormerlySerializedAs?
When I use it I add the header, save, rename, save, remove header, save, and it STILL loses all inspector references
ah is that this SceneManager.sceneLoaded += OnSceneLoaded
yes
the docs give you a perfect example to compare to
did you look at the method signature in the example code linked?
all i can see is putting it in onEnable but thats still giving me the error
compare your OnSceneLoaded method to the docs
Add header, rename, save, switch to Unity and let it recompile, remove header, save
method signature!
i had my params in my loadNextScene not OnSceneLoaded
you need to pay more attention to what you are doing!
Can animation controller be used for same purpose as state machine or behaviour trees?
the animator is a state machine so it can be used for that yes, behavior trees would likely be difficult in it but you can use unity's Behavior package for that
I'd look out for performance though
Animator has an overhead cost since it's designed to blend many layers of properties when animating them
I will check it out
Why do some features come in unity seperately as packages be installed instead of just being preinstalled?
because not every project need them, why pay the overhead for things you dont want?
well for one thing, the behavior package only just released. and not everything needs to be directly integrated into the engine, the more things are modularized, the more your experience can be tailored to exactly what you need
Ok i get it.
this also pops in OnGUI.. :/
of course, when you change the toggle
no, every time..
nah
oh nvm.. the != value didn't work properly
`using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MovementPlayer1 : MonoBehaviour
{
private float movingspeed = 10;
private float diry;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (name == "Player1")
{
diry = Input.GetAxisRaw("Vertical") * movingspeed;
}
if (name ="Player2" && Input.anyKey) //<-- Right here
{
if (Input.GetKey(KeyCode.I))
{
diry = movingspeed;
}
if (Input.GetKey(KeyCode.K))
{
diry = -movingspeed;
}
}
else if (!Input.anyKey)
{
diry = 0f;
}
}
}`
I searched online for half an hour and i cant find out why unity doesnt like that i use a && in the if condition...
name == "Player2". you forgot a =
thank u so much i was really doubting my programmingskills rn 👍
"SetDestination" can only be called on an active agent that has been placed on a NavMesh.
UnityEngine.AI.NavMeshAgent:set_destination (UnityEngine.Vector3), how can i fix this error? because my game wont start either, this is the script ive been using: https://gdl.space/mamivalena.cpp
have you placed a navmesh and baked it? your ai agents need it
Pretty clear error - make sure the NMA you referenced is active and on a navmesh
yeah i did, but at first the blue "ground" was there, and later it dissapeared
maybe it disappeared cause you disabled the object it was on? or maybe you gotta re-bake it
i just re bake it a second ago and nothing happened
So i want to get the Axis of the Mouse X (and y) without the value going to a negative value, but the Horizontal and Vertical ranges change from 0 to +1 or -1. i want to get the axis of the mouse at only a positive value whenever you move ur mouse, is there soemthing that might do that?
Mathf.abs
Followed exactly and it still wiped all the references. This is ridiculous
what does this mean exactly? Like only capturing rightward and upward mouse movement?
or do you want [-1, 1] to become [0, 1] ?
Or something else?
FYI if you're still interested in this or haven't figured it out on your own, that asset is now free.
oh great
thanks for letting me know
i'll check it out
it kinda looks like when i try to bake it it stops in the middle and nothing is showing up
do you have gizmos enabled and the navmesh surface object selected in the hierarchy?
yes and yes
well those screenshots aren't very helpful at all. if at this point you've determined that your navmesh is not baking, then the issue is likely whatever settings you have for the navmesh surface. share the relevant setup details in #🤖┃ai-navigation
alr sorry for that
Hello, what would people consider a comprehensive Unity course for someone already knowing C#? In the search I found people discourage paid courses, but not sure what else would be recommended?
LIke, sure, I can look up 50 different YouTube tutorials (though I've heard mixed opinions on those too), but is there something nice and comprehensive by a single person/string of videos? I tend to prefer that than different teaching styles etc
!learn
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
Neat, thanks
Hey i have a Problem where i try to set a Variable of a Script (added to an Object) via the inspector. In my code the corresponding lines are
[SerializeField] private InputField FieldA;
[SerializeField] private Text FieldB;
but i cant drag and drop or choose the corresponding Inputfield / Text Object. any1 know what i am doing wrong?
your components are probably the text mesh pro ones not the legacy ones, so your variable types need to match. TMP_InputField and TMP_Text
so
[SerializeField] private TMP_InputField FieldA;
[SerializeField] private TMP_Text FieldB; ?
if my guess about the actual components was right, then yes
do i need extra using directives now ?
using TMPro
yes, your !IDE should have suggested or autofilled them when you used that. assuming it is configured
If your IDE is not autocompleting code
or underlining errors, please configure it.
Select one:
•
Visual Studio (Installed via Unity Hub)
•
Visual Studio (Installed manually)
•
VS Code
•
JetBrains Rider
• :question: Other/None
❤️ Legends thank you
How do i use .parent to check for the closest parent?
You would loop though all the parents around you
And find the distance between each one of them to you
Anyone mind helping me so solve these errors?
probably missing some packages or using the wrong names
{
Debug.Log("Key 1 is pressed");
transform.GetChild(0).GetComponent<Image>().enabled = false;
}
if (isSelected == null)
{
Debug.LogError("isSelected Image is not assigned in the Inspector!");
}
else
{
Debug.Log("isSelected Image assigned successfully.");
}``` It saying "NullReferenceException: Object reference not set to an instance of an object
Slots.Update () (at Assets/Scripts/Slots.cs:33)" but i have the image in the slot can some help ChatGPT is being useless. im not sure what info is usefull so please ask if you need more
whats line 33?
transform.GetChild(0).GetComponent<TextMeshProUGUI>().enabled = false;
it was all working intell i wanted that select thing
its all from a tutoral but that other part im adding
so does the 0th child of the object with this script have a text mesh pro UI component?
oh wow it was that simple. I had the image as the first one
This is one reason it's better to just assign the component in the inspector
which is possible even if its a prefab since its on 1 game object
I have 9 slots and they are under inventory which is under a canvas. If i make it a componet will they all change at once?
If you make what a component will all of what change at once? And in response to what action?
using System.Collections.Generic;
using UnityEngine;
using TMPro;
using UnityEngine.UI;
public class Slots : MonoBehaviour
{
private InventoryController inventory;
public int i;
public TextMeshProUGUI amountText;
public Image isSelected;
public int amount;
// Start is called before the first frame update
void Start()
{
inventory = FindObjectOfType<InventoryController>();
}
// Update is called once per frame
void Update()
{
amountText.text = amount.ToString();
//Turns off text if nothings there
if (amount >= 1)
{
transform.GetChild(0).GetComponent<TextMeshProUGUI>().enabled = true; //The 1(it starts from 0) is the first child under slot (1), amount. It then gets a component which is TextMeshProUGUI. It then enables it(the checkmark)
}
else
{
transform.GetChild(0).GetComponent<TextMeshProUGUI>().enabled = false;
}
if (transform.childCount == 3)//This is the amount of child under the slot if add more gui change this number
{
inventory.isFull[i] = false;
}
if (Input.GetKeyDown(KeyCode.Alpha1))
{
Debug.Log("Key 1 is pressed");
isSelected.enabled = false;
}
}
public void DropItem()
{
if (amount > 1) //If its stacked
{
amount -= 1;
transform.GetComponentInChildren<Spawn>().SpawnDroppedItem(); //I think that last part is calling the function in spawn script
}
else if (amount == 1)
{
amount -= 1;
GameObject.Destroy(transform.GetComponentInChildren<Spawn>().gameObject);
transform.GetComponentInChildren<Spawn>().SpawnDroppedItem();
}
}
}
sorry i forget you can see everything i can. the slots have a counter if the items in it and the number turns off if there not an item in it
im just confused on how it knows which of the 9 to turn off.
Nevermind every thing
i just figured it out
The TextMeshProUGUI component on this object's first child
It knows which one to turn off because that's the one you've told it to turn off
ya the thing im trying to add is throwing me off my i think i got it now
ChatGPT is being useless
Thats why you learn how to code and how to use the engine and not just copy code from AI, cuz if it fails youre lost.
!learn
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
All AI knows is related topics from the internet, so if those topics are wrong, it will be inheritly wrong. thats why we do not suggest AI for coding since its also better to use your brain which is supposed to be able to constructive think and critical think to solve an issue.
and its better to actually understand what you are doing rather than mindlessly doing it
you learn more by reading through those 50 topics to get the answer. it's the journey (along the way), not the result . . .
then you have an understanding of the problem and how to solve it, instead of just the code for the solution . . .
that's a big difference . . .
At this point, we might need some message to link about this conversation considering it gets suggested to beginners so often.
Though I dont really understand what they were suggesting, since one message says to learn properly and the next says to use AI instead of google.
yes the time saved i didnt waste on searching for the same result
cuz the AI even explains it to you
sure it does that, thats why im saying you should learn how to code and have a good basis before using chatgpt
(Assuming the AI explains correctly and doesn't invent things from thin air)
Asking for a lot there
you shouldnt use ChatGPT Free or the generic prompt, you would need one of the specialised gpts
And the lowend free version is garbolium, i should mention that
so if your trial GPT4 prompts runs out, you should stop using it or pay for the full version
nope
using it multiple times a week, so far none of the specialised gpts have hallucinated
you should not use chatgpt if its wrong then?
why use a tool thats wrong? and has proven to be wrong
it is basically never wrong, but you should have enough knowledge so you can tell if its glitching out and giving bs code
I mean, it can be a neat tool. Just whenever I used it, it usually eventually spits out something wrong and when I try to correct itself on it it either
a) claims it corrected but spits out the same code or
b) gives completely different code that has some new issue
if were talking GPT 3.5 yes that was really bad, but since GPT 4 and the specialised GPTs it has gotten a lot better
K whatever you say then, im not gonna argue an arbitrary point just to be correct 🤷♂️
i would guess youre using the free gpt version
since that likes to do that, especially the claims it corrected but spits out the same code
I think even waht I tried of 4 did that a bunch. Maybe less with Unity, idk. It wasn't great at Rust
Why pay for the plaigarism machine
or just the general ChatGPT prompt that isnt trained on a language
you could probably pay an actual tutor instead
or use critical thinking and documentation
what do i need a tutor for, i know how to code, its just a faster google
if you have to rely on GPT as a tool then you're not learning much
Well there's a difference between knowing when it spits out stupid stuff and just using it as a google-like
And not knowing when it tells you made up stuff
it gives me the correct thing i need and even an example and how to implement it and if i need more info it can link me to relevant posts
no need to waste 20 min on google going trough forums or stackoverflow
How much are you paying versus how long does it take you to google something?
you just just not should want it to provide code for you, like "program me a loop that does this and then that and returns something else"
why don't you just write it yourself, thats much quicker 😮
thats most likely gonna be garbage code
thats what im doing
idk if yall cant read
this
I just joined what’s going on
trolloing
you use it to get specific help or like functions, not to get entire code and it works wonderfully
thats a contradiction to what you said after
AI especially Chatgpt 4s specialised coding Chats are very good at coding, if you can give it specific tasks and ask for specific help
Its way faster then googling and searching trough 50 topics
no ?
if you can give it specific tasks and ask for specific help
Its way faster then googling and searching trough 50 topics
not for generic coding stuff
what? I don’t understand.
Literally what are you googling for that you can't like, immediately find?
What are you googling that requires searching through that many topics
there is so many stuff in C# and Unity thats not directly explained and you have like 40 different threads with a different answer, unless you are a complete beginner
saying the same thing to chatgpt gives you a summary and the most liked implementation
the documentation explains them very well
If there's that much conflicting info, I dunno why the AI would know the silver bullet, but eh
cuz the ai has all of them and can tell which the people like more and like less and then shows you the best option
its like an optimized search engine
I'm going to doubt the "has all of them" part
its litterally a web scraper
it has all of em
if it doesnt, it can scrape more sites for you
did you know the internet also has all of them
How do I know if it does or does not have all of them and thus need or don't need to tell it to scrape more
get an answer that explains it well and works ? no.
doesnt ? tell it you need more input and it should look online
So, if you are willing to pay money and download a chatbot, you can get type your message into a different page than google and get the same information at roughly the same rate
Totally worthwhile
Well, it working and explaining it well doesn't necessarily mean it's the best way
its litterally a prompt like on google, but instead of searching you get an immediate answer
you do realize you can just use 1 google search to find your answer?
thats not really necessary, overoptimization or overimproving is a bad idea
otherwise known as guugle
if it works and doesnt steal you 50 fps it does the job
well you said the AI has all and can show the best option
code to get stuff done, dont code to code pretty & optimized
it usually does, but if doesnt, it wont matter. thats what i mean
you would most likely code and make it optimized so it doesnt turn your computer into a dumpster fire
what
you make optimized code and working code
I don't really know what you're getting at on this one either
I can't really vouch for how good the paid chatbots are because seriously who the hell spends money on the plaigarism machine, but I think you're vastly overestimating how long it takes to google basically anything programming related
im a programmer since im 12, im now 25, i have googled so many programming stuff and i hell i do be searching around 5-25 different websites till i find a good answer sometimes on more niche questions, while chatgpt just goes: "I got you: answer"
Thats a huge value for 20$ a month in saved time
It's 2024, there aren't even 25 total websites any more
there's like twelve websites on the entire internet
Any problem you'll search for will take you to either the documentation or StackOverflow

It's seriously not hard to find anything. Data has been collected into these monolithic Websites of Alexandria
im using this since GPT 4 (April), there are still so many random blogs and sometimes 12 different stackoverflow & 20 different reddit posts about one thing, prolly even more then 8 years ago
and then the next thing is so niche you only find a random ass article from 2015
Okay but why would you click on any of those
to get an answer to my question, honestly this is useless, i tried to proove the point, but im talking against a wall with you guys

I feel like I've given a pretty solid response - googling is not hard and saving half a second is not worth $20
you dont even save half a second. This is just not knowing how to google. This is why at the start i said we should have some message or something we can link to for others to read about why you shouldnt suggest it to beginners. The ones using AI always like to just say "its never made up things that seems truthful to me!". Well either it has, or you're asking it to make for loops.
This is just not knowing how to google. yep sure buddy 👍
...yes it is? Not sure what the sarcasm is supposed to mean when that's literally the point
You've said you find googling too difficult
That's why you pay $20 for a chatbot to google for you
not at all what i said, yeah im right im talking to a wall, not worth to continue
bye
How else can you interpret it?
My point is more for the beginners that see this conversation and want to justify their use of AI.
But everytime someone advocates for AI its always the exact same conversation everytime. "It works for me why wont you guys listen". Yea ive went through the whole AI phase too. when I needed it for something else, i figured i might as well try out the coding side of it. It was horrible, yes even on gpt4. Sure you could ask it to make a for loop for you, and itll do it. But as soon as you want something above what a first year programmer can do, you're stuck on this cycle of "well if i just adjust my prompt maybe itll understand me this time!".
And anyways, you claim you're talking to a wall while repeating the same points we've seen dozens of times and clearly show you dont know how to google by your own points. I havent seen you actually address a point other than saying "chatgpt can do it without going through 50 links"
I havent seen you actually address a point other than saying "chatgpt can do it without going through 50 links
cuz thats my main point ? It can answer your questions about programming and functions or implementations, without you needing to search for ages;
but it cant really code for you, litterally the first thing i said about it at the beginning... oh boy
So you are saying that googling is too hard. You don't have to go through 50 links. Most of the time you don't even have to click on anything
this
please read what you're typing.
but it cant really code for you, litterally the first thing i said about it at the beginning
#💻┃code-beginner message
AI especially Chatgpt 4s specialised coding Chats are very good at coding
"Most of the time you don't even have to click on anything" Thats not even remotly how it works
or youre searching for really simple stuff
but more complicated stuff you will have to go trough 2-3 posts minimum, extracting all the info, while chatgpt already has all that info can can just give it to you
thats what its useful for
and since gpt free has a worse database and cant do webscraping, its basically useless in general
Literally what are you looking for that isn't readily available basically immediately
thats false since google itself shows you on the front page of your search for your answer sometimes
its a built in function of google
and the descriptions of sites also tells you a lot
that happend maybe once to me, thats so rare lol
information that isnt immediately on google but somehow webscraped from gpt apparently.
what? its not
cuz chatgpt is not google ?
remind me of those late night infomercials , they make everything seem/look so difficult and inconvenient .
ok i just tried it, did they change that to be more agressive this year ?
i tried it last year and it barly ever popped up
its been that way forever, you have been in the GPT loop lmao
yeah ive been so loong in the gpt loop, man 6 months
anyways, the main point of this is not to suggest other beginners to use AI. No one really cares if you insist on using it. I found a thread where we talked about it before
https://discord.com/channels/489222168727519232/1267346441270067222
anyone know how to tint an object a certain color when mousing over it rather than changing its color entirely?
i have an object that's disabled by default over the tile that activates when you mouse over it, but the highlight flickers rapidly
How are you handling the color change currently?
well i did not
i did the opposite
so why we even arguing
lol
the tiles themselves don't change color, there's an object of a certain color on top of them disabled by default
it activates when you mouse over it (void OnMouseOver) and deactivates using OnMouseExit()
the problem is the object on/off rapidly
(this also means this isn't a tint i know)
idk if you're trolling here now or really just dont remember what you wrote, in multiple messages you're here advocating for the use of AI in the beginner channel. What else do you think you're doing?
#💻┃code-beginner message
#💻┃code-beginner message
you should show !code
📃 Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
but if theres an object on top, then your mouse probably isnt over the same object anymore
So, you move the mouse over this object, and you activate a new object that's on top of it. This means that your mouse is now over that object instead, which means this object disables that one, which means your mouse is now on top of it again
and so on
Yeah i just realised how that sounds in this channel without much context
yeah the whole discussion was completly my bad

But yeah you @eternal needle @polar acorn @steep rose convinced me to give googling another chance even if gpt works for me, maybe its not worth it throwing money at them for faster results.
Thanks guys
why is it not visible?
is it cause its static?
well it cant be cause of that
they are scriptable objects
will do, gimme a sec
this makes sense tho
thats why it’s flickering
yes
so whats the most logical fix to this
make them not be static
i need them static
then you can't set them in the inspector
brudda
cause i cant be asked to write .Instance
Get over it
use new input system with events ?
i dont like the new input system
cant get into it
and dont have time to get into it
oh alr , just makes what you're doing easier
i know it does
but i just dont have the time to learn it
i tried it before
wasted over 2 months
2 months? tbh it took me a few days, there are not just 1 way to use thats why
true
I can't post the dismissive message because of the bot but it really is all that can be said
making coroutines worse 
heck ya
I hope they totally remove obsolete methods and members on unity6
Random.RandomRange sux
why cant you pass in multiple variables through an event?
like in a button
it can only be 1
i jumped on the bandwagon
i was trying to make it read better..
but no luck
I have a version that uses a singleton and doesnt need the this part
it actually reads better the way it is originally lol
Because that's how it was designed. You can pass as many as you want via code.
using the Mono then .Run(Coroutine)
you can.
just b/c it cant be done via the inspector doesn't mean it cant.
the only problem is that I hate writing startcoroutine in full, in my version, you can just type your ienumerator, and since i enumerator is a small interface, you just press s and the start is easy to select
if it helps you go for it
can just fix it later with a single magic regex lol
having me explain how my brain works just wasted back the time saved by doing this weird stunt tho lol
thought there mighta been something there.. that i could add to my utils class
alas.. dont think so for me lol
yeah i know through code
but i meant like visually
through the editor
StartCoroutine(Rebound()); ftw
y'all trying to make a coroutine act like a method...?
maybe in another world, you can call your coroutines only with Rebound()
Rebound() as Coroutine; or Coroutine.Rebound(); <-- yea that
would be dope
actually maybe I'll try looking at coroutine class lol
Unless you implement your own event that allows it, you're out of options.🤷♂️
the second is very unlikely
ya, but its cooler
alright thanks
the first one could be possible at least
why not the second? you could use ur own Coroutine class.
wrap it in a namespace
nvm that would refactor back to what the original is
https://hatebin.com/quvwuosrqj
this code handles the renderer, material, and color of the object
tried adding a while (true) loop to the OnMouseOver() method but that proved to be really bad
guess i could separate this code and add it to the object on the tile prefab, unless there's an easier way to do a tint effect?
Of course it didn't, how could that loop ever end
when I add my animation triggers they just play forever by deafult when i start the game. how do i stop that from happening?? I disabled "Loop Time" by clicking on the animation but it didnt do anything
was hoping the while loop would only be active while the SetActive was true
depends where you're calling trigger function also what conditions you made for transitions in animator
while(true) will run until one of the two conditions is met:
- A
breakstatement is reached - Every moving particle in the cosmos has reached its highest entropy state, and all that existed and ever will becomes stagnant, cold, and dead
all I've really done is placed the animations into the Animator, and added Triggers and then assign those triggers to said animations. I haven't added any calls to those triggers in script yet.
don't
Added Triggers is pretty vague also, if there aren't any scripts this isn't a code question.
#🏃┃animation and would show w/ screenshots all the said triggers you added
okay thank you! i had no idea there was a channel for that.
This isn't seeming to work either. The cube on this Tile3D object has the script attached, and I also made it so the Rendering mode is Transparent. OnMouseEnter isn't activating at all now.
Instead of toggling an object, why not just recolor this object?
if the gameobject is deactivated not sure unity runs those functions
also GetComponent<GameObject>() is redundant as you can just get the gameobject with the property gameObject VS is trying to hint you at that
like referencing the alpha value?
if its a mesh, switch the material or use the color parameter on the material's shader
You want to change the color when you mouse over it, right?
You can just change the color of the material or whatever other kind of renderer it's using
ah
oh, see that’s strange cause VS suggested doing GetComponent first, odd
i see now tho
one is the prediction / intellicode in VS, the warning comes from Unity message / library
both are not exactly talking to eachother
Okay so I made sure the game object isn't disabled by default, but the OnMouseEnter code still isn't executing
it has a box collider and everything
unless it needs a box collider bigger than it
also put logs to always test if a function is running
okay the script isn't even activating
okay i found it, had another SetActive(false) somewhere
The parent object in the prefab was setting it inactive
btw you should consider using a Raycast instead or even just the Event System with the Ipointer interfaces
you can have a bit more control on the hits / debugging information about hit objects
!bug
🪲 To make bug reporting as quickly as possible, we made a bug reporting application for you. When running Unity choose Help->Report a Bug in the menu, or you can access it directly through the executable in the directory where Unity is installed. It will also launch automatically if you experience a crash.
📝 If your bug report is to do with Documentation, either an error, typo, or omission, you can report it by scrolling to the bottom of the page where you found the issue and click ‘Report a problem on this page’!
💡If your report is to do with a new feature idea, you can check the Unity Product Roadmaps page to see if your idea has already been planned.
For more complete instructions on how to report bugs, access: https://unity3d.com/unity/qa/bug-reporting
i need help with some code i’m getting an error code and have no idea how to fix it
!code
📃 Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
//cs
How do i learn coding?
I was in the middle of doing a unity course, then decided to make a small project, i then went to the first tutorial that looked decent but i feel overwhelmed.
the tutorial doesn't seem bad but i'm unsure how do i learn code.
Should i understand every line here?
Should i just copy paste code even if i don't 100% understand how it works to focus on finishing my project?
What is the best aproach to learn?
ttorial is this by the way:https://youtu.be/f473C43s8nE
FIRST PERSON MOVEMENT in 10 MINUTES - Unity Tutorial
In this video I'm going to show you how to code full first person rigidbody movement. You can use this character controller as final movement for your game or build things like dashing, wallrunning or sliding on top of it.
If this tutorial has helped you in any way, I would really appreciate...
Ive never seen this yet - is this just a unity bug? 'Unity self'
ArgumentNullException: Value cannot be null.
Parameter name: _unity_self
UnityEditor.SerializedObject.FindProperty (System.String propertyPath) (at <9920ff0c944845d7b9f9a61ef1478edc>:0)
UnityEditor.UIElements.Bindings.SerializedObjectBindingContext.BindPropertyRelative (UnityEngine.UIElements.IBindable field, UnityEditor.SerializedProperty parentProperty) (at <8c3449848bd845499081ddbe4a09b367>:0)
UnityEditor.UIElements.Bindings.SerializedObjectBindingContext.BindTree (UnityEngine.UIElements.VisualElement element, UnityEditor.SerializedProperty parentProperty) (at <8c3449848bd845499081ddbe4a09b367>:0)
UnityEditor.UIElements.Bindings.SerializedObjectBindingContext.ContinueBinding (UnityEngine.UIElements.VisualElement element, UnityEditor.SerializedProperty parentProperty) (at <8c3449848bd845499081ddbe4a09b367>:0)
UnityEditor.UIElements.Bindings.DefaultSerializedObjectBindingImplementation+BindingRequest.Bind (UnityEngine.UIElements.VisualElement element) (at <8c3449848bd845499081ddbe4a09b367>:0)
UnityEngine.UIElements.VisualTreeBindingsUpdater.Update () (at <7c69dfc1e63a4ea388c73014d3c7ce20>:0)
UnityEngine.UIElements.VisualTreeUpdater.UpdateVisualTreePhase (UnityEngine.UIElements.VisualTreeUpdatePhase phase) (at <7c69dfc1e63a4ea388c73014d3c7ce20>:0)
UnityEngine.UIElements.Panel.UpdateBindings () (at <7c69dfc1e63a4ea388c73014d3c7ce20>:0)
UnityEngine.UIElements.UIElementsUtility.UnityEngine.UIElements.IUIElementsUtility.UpdateSchedulers () (at <7c69dfc1e63a4ea388c73014d3c7ce20>:0)
UnityEngine.UIElements.UIEventRegistration.UpdateSchedulers () (at <7c69dfc1e63a4ea388c73014d3c7ce20>:0)
UnityEditor.RetainedMode.UpdateSchedulers () (at <8c3449848bd845499081ddbe4a09b367>:0)
It's solved on relaunching the project but I'm not exactly sure what I did to trigger it in the first place
how would i do that?
need help with code line 26 must have a return value https://hastebin.com/share/dafadimuwo.csharp
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
I suggest doing c# outside of unity so you can understand the basics like loops, data types, class, and just generally how to write code without all the unity stuff causing extra confusion. Ultimately you learn by doing, look at the docs when you dont understand something.
Yes it's a unity bug, if it's not reappearing it's fine to just ignore.
the c# function declaration is structured as follows
access modifier - return type - methodname (parameters)
eg
private void Foo(int number)
Is this AI code? This is quite a beginner error compared to the complexity of your code
If it's a tutorial you should follow it exactly but also I suggest the same to you as I did the other person here
#💻┃code-beginner message
yt code lol i've been taking coding classes but I wasn't understanding that portion of it
thank you this makes a lot more sense
Hi all! I've been working on a basic first person game, and I wanted to use ray casts to shoot out to deal with a player interacting with the object they're looking at, and I have some basic code online using Debug.DrawLine that should just project a ray from the player's view to where they're looking but for some reason no matter how I program it, the ray always starts at the camera (Like its supposed too) but it will only point towards the ground no matter where the player moves. Im pretty stumped here as I've tried a bunch of different methods of fixing it
going to have to show some !code
use drawray
📃 Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
also for rays yes you should use DrawRay, or even better Physics Debugger
oh my god thats what it was
i've spent at least 5 hours trying to figure it out and it was literally just that, ive been going insane
thank you so much
i dont know how in all my searching I didnt realize I was just using the wrong debug 😭
much easier to use physics debugger these days , hardly need to draw physics queries anymore
makes code repetitive, if you change raycast you gotta remember to match the debug n vice versa
I was mostly using the draw debugging to make sure I was understanding rays correctly before I attempted to implement it
I didnt wanna implement the system unless I knew exactly how it was acting visually
yup, give physics debugger a try
https://docs.unity3d.com/6000.0/Documentation/Manual/PhysicsDebugVisualization.html#physics-debug-queries
thanks!
I would look at the documentation if you are confused on what it is and what It does
But yes do what navarone said, I didn't know that existed 😂
Unless it is a unity 6 thing, then I definitely wouldnt have known
its 2022+
I just linked 6 docs cause 2022 is being weird lol
Ah okay good to know, I guess I'm just living under a bunch of nested if statements 😄
its lowkey a good feature to have especially for visualizing Spherecasts n such
wtf i think unity is struggling with simple division
check the variable named A, it is just for debugging and is simply the values of velocity x/y
not only does it ignore that i try to make it negative, but the division itself is way off
unlikely. you're probably missing something elsewhere
computers don't struggle with basic division
you should probably verify the math in a debug.log rather than the inspector
you are right, debug log shows the correct result
You're changing vectorVel after calculating A so yeah you're just seeing the new value of vectorVel and the A calculated from the old value in the inspector
Debug.Log($"-({vectorVel.x} / {vectorVel.y}) = {a}");
Right after the line
yeah, specifically im disabling a renderer until a player first looks away from the collider, then ill change the collider layer to include the player and then enable the renderer, but ive got it working and if anyone else is interested in raycasting the entire camera this is what i came up with
// in FixedUpate()
Vector3[] frustumCorners = new Vector3[4];
camera.CalculateFrustumCorners(new Rect(0, 0, 1, 1), camera.farClipPlane, Camera.MonoOrStereoscopicEye.Mono, frustumCorners);
Vector3 topLeft = frustumCorners[1];
Vector3 topRight = frustumCorners[2];
Vector3 bottomLeft = frustumCorners[0];
Vector3 bottomRight = frustumCorners[3];
Vector3 vertical = bottomLeft - topLeft;
Vector3 horizontal = topRight - topLeft;
int vAmount = 4;
int hAmount = 8;
for (int i = 0; i < vAmount; i++)
{
for (int j = 0; j < hAmount; j++)
{
Vector3 point = topLeft + (((vertical) / vAmount ) * i) + (((horizontal) / hAmount ) * j);
point = camera.transform.TransformVector(point);
// Debug.DrawRay(camera.transform.position, point, Color.blue);
if (Physics.Raycast(camera.transform.position, point, out RaycastHit hit))
{
if (hit.collider.gameObject.TryGetComponent(out ICameraSenseable senseable))
{
senseable._CameraViewFixedUpdate();
}
}
}
}
Still not sure what's the point of that. It's like checking against the frustum planes(+ maybe one raycast), just a lot less accurate.
And probably less performant.
It is pointless to create occlusion culling by yourself. The engine has it's own ways and it should get updated by them in order to make system stable. This is because they are the ones who can implement a system that is optimized very well since they can implement to the core of the engine. Even tho Unity 5 have Occlusion Culling, it is not enough for large worlds due to floating point errors and Unity provide no support for floating point while Unreal does. In Unity 6, they just updated the Occlusion Culling and told users that is a game changing shit but the same technology (GPU based OC) was always been there in Unreal...
So still, if you want a large open world, you COULD use Unity 6 or switch to Unreal for really better performance.
that tutorial is complex and not the best (for starters), ive used it multiple times
Dont even try making first person games when you just start, make random cubes and spheres games
is it possible for some Start() to be called first before other object's Awake()?
Or did I do something horribly wrong...
Theoretically, possible. For example if the the object with awake is disabled on scene load.
Yeah that makes sense, thanks man
Let's say I have a prefab. It's an empty gameobject with a model as a child. I would like to change specifically the material of the child to be a certain color. How would I do this?
To answer my own question: GetComponentsInChildren
Also, it would be wise to not have the same component in the hierarchy of the prefab
depends on what the material is, as color variables could have different names in the shader code, but usually it's just _Color. So, something like
var newColor = Color.white;
yourParentObject.GetComponentInChildren<MeshRenderer>().material.SetColor("_Color", newColor);
Ah, yeah that would work too, so long as I don't have the component on the parent, which was my big mistake
if you are dealing with child objects, usually it's good to make a new script to put on the parent so that you can assign references there
relying on GetComponentInChildren / Parent is not usually ideal
Is doing Vector3.Dot(Vector3.up, myDirection) an effective way of finding the upward component of a vector or do I need to do actual trig? (Vector3.up could be the up of any vector, so .y doesn’t apply)
What do you mean the upward component? Can you specify what you're trying to solve with this
So I’m trying to do some vehicle physics stuff (don’t want to use wheel colliders) and having the right force be pushed back up from the ground is proving tough, so if I wanted to isolate just the force acting downwards after it’s acted through the suspension is it doable with .Dot or will I need to do trig?
(I may also just be entirely over thinking this and I can just have my suspension calculation handle gravity too idk)
If you want only the up/downwards force just take the y component of the vecror
I'm not really sure what you mean in the first message saying .y doesnt apply
But if it wasn’t up/down according to world space?
Rather up/down according to a normal?
Wait I think I’m overthinking this anyway
I'm not really sure what you're doing here, and I'm not too good with physics but I suggest you read this https://docs.unity3d.com/ScriptReference/Vector3.Dot.html
It just returns a float, so I guess you could compare how similar your vector is to some other vector but I'm not sure what you're trying to do with it.
In a rigidbody you can add a mass, mabye you can try that too? Im no expert btw
Yeah I’m using mass and gravity for the weight but countering the weight is a perpetual headache, I can never decide how I want to do it lol
I think I have it now though
Hello so I was creating a game where I need to throw food at my pan and then take the pan to the counter
- After throwing the food it goes inside pan
- but as soon as in move with the pan the food falls down
- I want to make it move with pan and fall when I rotate it 90 degrees
so parent the food to the pan and then unparent it when you rotate
The food is instantiating don’t want it to parent as soon as it instantiates ( drops )
Should I use enumeration or something
so you parent it when the food hits the pan
Will try it basically the game is mining food ⛏️ so while mining it instantiates the food and it drops in the pan- excavator
Sorry couldnt find any other channel for this. Haven worked wih 3d i unity before and cant seem to find a way for a parent not to include its children when calculating its bounds. This is quite annoying since I want to rotate a object from a custom pivot and I thought just adding a parent could be done to controll the pivot (as you do in any other 3d package) and with 2d
Seems lite there is something really basic I missed
not sure how bounds has anything to do with this
If you just rotate it seems to do it around the center of the bounds
With childeren:
Without
@languid spire as you can see the pivot changed when adding a child
Change this to Pivot
Does that set it so that it also effects rotations in code?
No, only the editor
Ok its maybe just an editor problem then? When roating the parent it will have a pivot at it position in world space?
No, it didn't. You're just not actually looking at the Pivot
Well it uses the center for the pivot rotation so technically it is a pivot just not the Pivot
but yes you are right
Only the editor does that. In code that setting doesn't exist and has no meaning. The actual pivot is always what matters
Thats great then its just a editor problem that really isnt a problem
I have these 3 variables (The bloodSacrificeChance and the 2 below it,) and when I set them up in the start method and then debug them they equal to what they should but when I use them in a diffrent method in thescript they just change to 0 for some reason and the isBloodUsed changes to false
the variables 3 at the top
for example when I debug them in this method they are equal to 0
Show full !code
📃 Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
So, in the Act() coroutine, they're 0, where do you start this coroutine since it's not in this script?
in the enemyTurn method
in line 312
Okay, so, you're calling it on the instance in the enemiesLibrary. I'm assuming that's set in the inspector, since it's serialized. Can you show me the inspector for the EnemiesLibrary component?
Okay, so, the knight unit is the one with problem, right? Double click on that box in this inspector, show the object that comes up
using System.Collections.Generic;
using UnityEngine;
public class verschijnfuse : MonoBehaviour
{
public fuseskript fuse;
void Start()
{
// Controleer of dit object de tag "fuse" heeft
if (gameObject.CompareTag("fuse"))
{
gameObject.SetActive(false);
}
}
// Update is called once per frame
public void place()
{
Debug.Log("Activating fuse object.");
gameObject.SetActive(true);
}
}```
why isn't my gameObject appearing?
What calls place()
wdym
So, it's a prefab. The prefab itself never enters the scene, so it's Start() function is never called
it like placing something
I mean what I asked, where do you call the place() function you made
Your EnemiesLibrary should reference the instances in the scene, rather than the prefabs. That way they'll have run their Start methods and whatnot
umm how do I do that?
What spawns the objects?
Okay, and what is ObjectInteraction? When does this call that function?
when i hover the object and click 'e'
wait when I think about it it does run the start method tho
You are spawning one. But you're calling Act() on the prefab, not the one you made
I found it, it's in SetupBattle
You're spawning a clone of enemyUnit, but then you're changing the prefab's currentHP and whatnot
i added a debug thingy and when i click e it shows the messages but it does not let the object appear.
me?
You probably want to store the return value of Instantiate in a variable and use that one
Are you doing anything involving enemyUnit, currentHP, or prefabs?
no but do you know the solution of my problem
So, you get the log saying "Activating fuse object."?
yup
Then this object is being enabled
but i can't see it
Show the inspector of the object with your verschijnfuse script on it after the log prints
umm tbh I'm still not that sure how exactly do I use that
Instantiate makes a copy of something and puts it in the scene. You're making a copy of your prefab and putting it in the scene. That copy then runs Start and sets its variables. enemyUnit is still the prefab that was not put in the scene and therefore has not set any of its variables in Start. Instead of using enemyUnit, you should use the thing that Instantiate created
it stays like this
that is not the correct gawme object
No, the object you're trying to activate, the one with the verschijnfuse script on it
this is the gameobject referenced. fuse1
but dont I use it already? the clone I mean
isn't that what instaniate is created
no
No, how would you? You don't store it in a variable
How would you reference it if you don't actually keep a reference to it?
I mean cuz its already in the scene
but not in your code
this objects dissapears when clicking on play. and it does not appears
There are many things you have in your scene. An object existing does not mean it's the one you're referencing
This script will disable the object it's on in Start, as long as this object has the tag "fuse". When place is called, it will reactivate itself. Now show the object that has this script on it
ok so after I stored the instantiate in a variable what do I do?
Okay, is this object active after your log prints?
Use that, instead of the prefab
yes when i click on that object the fuse should appear
Yes it has to be empty in the beginning, when i click on the object the fuse has to appear
How do I use that though
Show a screenshot of your full unity window, with the console visible, and this object selected, after your log has printed showing that place has been called
im sorry if it sounds dumb im just still not that great at coding
instead of using the variable that holds your prefab, use the variable that holds the one in the scene
I dont use a variable for the enemyPrefab tho
I mean I have one but I dont refrence it anywhere
Yes, you do. enemyUnit
The one you got from your enemy library
Scroll up to the top of this object in the inspector
so I should replace every place I write enemyUnit in the battlesystem script with the nameof the new variable?
Anywhere that you want to refer to the object in the scene instead of the prefab from the library
aight
no because the fuse does not appear when I click this object
You're activating the object that has the verschijnfuse script on it. This is the object that has that script on it. This object is active. The code is working.
Yes, the object is activated, but the fuse doesn't appear. It just stays dissappeared
That isn't working
Is there a parent of this object that is disabled
the parent is a whole object.
Also, this looks pretty visible to me
That's not this object though
The one you have selected is the one outlined in orange
That's the object you're activating, and it's active
This is the object your code is trying to activate, and it's active.
aight I did it and it accualy works now tnx @polar acorn
And what's telling this object to activate?
actually *
Hello, I was just wondering whether I should use Rigidbody for character movement. It would be a pretty basic movement, crouching and maybe mantling/hopping over objects. I cant decide if I should use Translate or Rigidbody. I am not really keen on the Character Controller component, as I think it would be easier for me to work with my code when implementing new stuff later on.
Your code's been referring to the Fuse1 object
this one. You gotta click on this object to make the fuse appear
You should probably never use Translate for a character. If you want it to interact with literally anything, it's going to need either Rigidbody or CharacterController
Okay, so why is this object trying to activate itself if you want it to activate a different object
Alright thanks :D
thats a good question
so i need to make 2 skripts for this action?
Or have your script toggle a different object instead of itself
Well i seperated them by using the tag 'fuse' so this object doesn't dissapear when you click on play
Your script is telling the object that it is on to enable or disable
void Start()
{
if (gameObject.CompareTag("fuse"))
{
gameObject.SetActive(false);
}
}
if you want it to enable or disable a different object, you should use that
So making 2 skripts will fix it?
You don't need two scripts
Just have this one reference a different GameObject and toggle that one
By calling SetActive on that object instead of this one
Sure, if Verdwijnfuse is a reference to the GameObject you want to toggle
Assets\scripts\verschijnfuse.cs(21,5): error CS0103: The name 'Verdwijnfuse' does not exist in the current context
Im getting this error.
What is Verdwijnfuse in this script
the object i want to appear/dissappear
Okay but in the script, where do you define the variable Verdwijnfuse
using System.Collections.Generic;
using UnityEngine;
public class verschijnfuse : MonoBehaviour
{
public fuseskript fuse;
void Start()
{
{
Verdwijnfuse.SetActive(false);
}
}
public void place()
{
Debug.Log("Activating fuse object.");
Verdwijnfuse.SetActive(true);
}
}```
There is nothing in this script named Verdwijnfuse
You have not made a variable of that name
UnassignedReferenceException: The variable Verdwijnfuse of verschijnfuse has not been assigned.
You probably need to assign the Verdwijnfuse variable of the verschijnfuse script in the inspector.
verschijnfuse.place () (at Assets/scripts/verschijnfuse.cs:20)
UnityEngine.Events.InvokableCall.Invoke () (at <0b78209fd00d4f419f30dd210cbab239>:0)
UnityEngine.Events.UnityEvent.Invoke () (at <0b78209fd00d4f419f30dd210cbab239>:0)
ObjectInteraction.OnInteract () (at Assets/scripts/ObjectInteraction.cs:25)
CameraLookDetector.Update () (at Assets/scripts/CameraLookDetector.cs:40)
now im getting this error
the object has a name
You have at least one instance of this script that you have not assigned a value to Verdwijnfuse
This one you've got pictured is fine, so it's not this one
it says the main camera when I dubble click the error,.
Does that object have a Verschijnfuse script on it?
no
So, you're going to have to find whatever object has that script on it, but doesn't have the variable Verdwijnfuse assigned
hello
i have 2 cameras in a scene
and i adjusted the rect of one camera to fit it in the other camera point of view
is it possible for the camera rect to rescale itself automatically with the changing size of the display just like UI elements?
it was this object
So i need to remove the skripts from this object? The one i use the skript to interact with?
Then you'll need to assign a value to it or remove the script
need help?
Thanks it works! Needed to add some more lines
!Learn
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
The camera rescales itself automatically to the aspect-ratio of the screen.
You can adjust the FOV and what axis the FOV is acted on.
not talking about the camera
but the rect
the rect of the camera in the display
oh. Is it using Unity UI?
anchoring with this should force an element to always fill the entire canvas.

If you're just talking about a normal rectangle as an object, then yeah, some simple math should do the trick.
Check the distance from the camera
then calculate the FOV on X and Y
then use sin and cos accordingly to find the X and Y -scaling of the object.
aha.
its a rect
not a rect transform
i never found a way to rescale rects
neither have i worked with plain Unity UI made with rects
well, to what purpose do you want to rescale the Viewport Rect?
I've never really had to do that in any of my projects, so I'm curious.
there might be a better solution for whatever you want to do.
I believe this can modify the camera rect
https://docs.unity3d.com/ScriptReference/Camera-rect.html
i could be wrong
since i have never used it
let me see
it does it randomly
just Camera.rect.*

thats just an example
randomly?
You can adjust the height and width respectively
you do not need to do that
if i place a UI element and copied its rect to match the rect of the camera then would it work?
I'm still not sure what you want to calculate.
you would have to try it
UI elements scale based on the camera by default.
I have no idea what you want to do right now.
rects are not
this might give you a better understanding
what in the world.
then best just mock something up using this function
also is that unity?
i dont know what im looking at
yes it is unity
Looks like Unity to me if we look at all the parameters. Everything else is INSANITY though.
i hooked some c++ libraries at runtime to achieve the result
not really hooking but just some C++ calls inside C#
thats on the border of not being unity 😆
but as i said
nah unity is really powerful tbh if you ask me
in terms of user control
seems like it
why'd you control it to make it look like... this.
prob preference
i have a goal and i dont think promotion is supported
I'm an open-minded individual but this... this is too far.
