#💻┃code-beginner
1 messages · Page 277 of 1
there should be a dot operator after the null check ?
OnInteactAction also doesn't exist
ok
TypeCache is unable to load attribute info on method Unity.QuickSearch.Providers.BoltProvider:CreateProvider (<unable to load signature>). Are you missing a reference?
but your ide should be pointing it out if you have it configured like you should
this is from the UnityQuickSearch package
not your code
update all your packages
and regenerate the library folder (by deleting it)
also restart Unity
Click regenerate project files right there
Did you do it while VS was closed
yeah
done, how do i regenerate or delete the lib folder?
You got the unity workload, right?
i even clicked the repaire button in the visual studio installer in case that works
It's one of the first parts of the guide you went though
It is part of installing vs
ah yeah i did check the game dev with unity along with unity hub
from windows explorer
Now I only get 2 errors
No need, errors got scared away
Just to be clear, i mean this
what is an identifier?
yeah yeah yeah as i said
Well what you said didn't make sense, so I wanted to make sure...
But alright. I dunno, sorry
yeah sorry
An identifier is a name for a variable or type or whatever
Most likely your line 20 is just completely off and weird
and the compiler doesn't know what to do
Especially if it still looks like this
Ahhh, I see what you mean by "along with unity hub" now. My bad
Maybe try regenerating project
I decapitalzied the "T" though and still get the error
shall i reinstall vs?
im having a bit of a problem. The script has a Start method which assigns a button component to the variable "button". I verified it that it actually gets the component but then when i use the variable. It says Null reference.
`public Button button;
private int desInt;
private void Start()
{
button = this.GetComponent<Button>();
}
public void AddListener(int index, SideBarManager insideBarManager)
{
sideBarManager = insideBarManager;
button.onClick.AddListener(this.SendWindowIndex);
desInt = index;
}
public void SendWindowIndex()
{
sideBarManager.ActivateNewWindow(desInt);
}`
i want to make a debug object that points in the direction of a vector i gave it, but it seems to be pointing at the normal of the vector?
void Update()
{
transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.LookRotation(Vector3.forward, cc.moveVector), 0.5f) ;
}```
Try Assets > Reimport All
doing it
the script is attached to the gameobject with the button component
that wasn't the only problem with this line
you're also using a delegate that doesn't exist (OnInteactAction)
And you're missing a . between the ? and the Invoke
Maybe the ide isn't configured? 
nothing changed
Did you reboot Visual Studio?
yeah i opened the file from unity after it booted up again
yes, the IDE should show Rigidbody2D in the same green color as a class
monobehavior should be colored as well
did you follow the !IDE guide?
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
• Other/None
They've gone through a lot by the time I attempted to help, best lookup the recent posts
Their history isn't too long
could always try vs code :)
where are you using the variable. which line says Null reference
this doesn’t look like a unity issue specifically, but that VS doesn’t acknowledge you are in C#
as opposed to VS not knowing you are in unity
are there extensions i have to install or smth?
are you on mac or windows?
win
this is so strange
ik :/
perhaps the C# discord can help
maybe something in the directories is messed up?
alr i'll check
i remember having this issue a month ago, and I can’t remember wtf i did to resolve it
but it is something very simple
hopefully
that's good to hear
Inside VS, in the solution explorer, if you right click the project, there should be something like "rebuild from dependencies" or something like that. Try clicking it
line 'button.onClick.AddListener(this.SendWindowIndex);'
yes
and where and when is AddListener called?
i have never had to click that, because I’m pretty sure VS does that automatically sometimes via unity
it is possible it never went for you
the function that the line is in
what do you have to lose? lol
Yep, that is the one
Its in another script
load failed
Hmmm very odd
okay, show the script?
yeah it's been showing (unloaded) already
u gave me hope
whole script? or just the important part?
where you call AddListener
what is it?
it failing to reload is a good sign, because now we know what the problem is
we don’t know exactly the fix, but it is narrowed down a lot
i remember learning gamedev before and i remember adding packages, i just don't seem to remember what it is
okay, where is CreateDraw called?
I want to know if you call it before or after the Start function of your first script
The method it is in happens from a different working button
does your project only have the one file in the solution?
How about just send the !code for both scripts so we can stop this game of telephone
📃 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.
that's good
you probably need to install extensions to VisualStudio
what r they?
Development with Unity
hold on lemme read the error
usually going through this should download everything you need.
i have it
Well that's great! 🙃
i misread it as a regular smiley mb
how can this.skill.Activate called while this.skill i null? can anyone give me an explaination for this?
the error says ".....\Assembly-CSharp.csproject.*.props" is not found
Were there any errors?
might start learning abt them
it’s like a group of code that all gets compiled together, with dependencies so compiler knows what blocks of code to compile to bring the whole project together
Okay, so CreateDraw is probably being called before Start. What calls CreateDraw?
no, but its just wierd
ok and that group of code that does this is missing?
this is the default assembly for Unity projects. All the random files and shit you make without an explicit assembly go into the assembly of this name
meaning VisualStudio can’t find that assembly file that it needs to put together the unity project
Can you show the entire console window from Unity Editor (it would show the warning, error and log counts)?
sooooo how is this fixable?
it literally tells VS the list of all the files for your project
either 1) Unity fucked up and didn’t make the assembly file, 2) Unity did make it, but VS can’t find it
soo how can i look for it
- Are you hiding errors in your console?
- Does
skillhave any sort of customToString? - (Wild shot in the dark) could it be that the skill is simply named null?
in case it exists
VS should find it since game development with unity is installed
or how can i know if unity made it in the first place
You can reset your External Tools inside the unity preferences window and see, if the correct IDE is set.
i don’t recall where. I think there should be a bunch of .dlls or something
The third one was a great suggestion
i don’t have the knowledge to fix this issue, but now we know exactly what it is
@ivory bobcat @polar acorn found the reason, its because skill derived from mono and unity dont allow creating a new class inherited from it
literally everyone says to regenerate project files
Yes, you should have gotten a warning on that in the console, always check those
yeah mb thx
you could try cleaning the solution but that has a slim chance of working
A button where the script is attached to
One of these days someone's gonna do this and it's gonna leave us baffled for like a week
he needs to know first if the issue is unity not making the assembly, or VS not finding it
that is an assembly that Unity is responsible for making.
Can you show an image of this?
I basically want to add a listener to a button i instantiated and give it a number
i'm looking up the problem in google
Okay, so, you're instantiating a new button, then immediately calling AddListener on it. Start hasn't run yet. Either assign the button variable of CustomButton in the inspector, or put the GetComponent in awake
Like this. But the prefab has empty
well u can barely see it in this image, now it's "load failed"
ic
Right click on the project and reload with dependencies
So it's caboose
It worked. Thanks. But a new error poped. But ill try to fix this
give me some hope 😂
Create a new project and copy the assets folder to it
ok i'll just create a new project, create a script, see if anything get's colored
but w8
well uhh, i found the file itself in github, idk if that helps
why cant i delete this file?
it says project still in use?
this is a project i wanna delete
i closed unity
all apps unity related
this is in the file exporter btw, i deleted it from unity hub library
Sounds like something is still open using it, your IDE perhaps?
Check your task manager and make sure there's no remaining Unity or IDE processes open
the thing is
i can see it
except the directory isn't the same
vs says i need to find it in the obj folder, while it is outside that folder
- it says the name of the file is Assembly-CSharp.csproj.*.props
all i can find in the "obj" folder is another "Debug" folder
does this work with other unity projects?
i'll create a new one and see
well NOW monobehavior is colored
yeah everything works fine
perfectly fine
but i still wanna fix my older project
Move your scene objects, assets and resources over.
Did you just try to backup and remove thewhole csproj files, let Unity try to regenerate it?
wait
all the csproj files in my project are outside the obj folder, while in the one i created, none is existing
but still the assembly file is outside the obj folder
this is the new one
this is the old one
Does this differ from the other project?
notice the scroll bar tho, it's a long list
Seems like you've got lots of extra stuff
I'm only aware of you having two assembly project files (maybe a concern)
No, you get loads of csproj files in the project folder.. depends on what you have in the project
uhhh soo what can i do
delete it
tho the error for the project not loading was the assembly file not existing in the obj folder
Reimport everything into the new project and pray the unwanted behavior is forever destroyed with the previous project.
alr
that what i recommended
yeah well i still want my project to be fixed
just copy'n paste the assets
for some reason those files showed up
Probably because of that carwash said #💻┃code-beginner message
They'll auto generate as you add/import stuff into your project
Likely had some corrupted file or (hopefully not) broken asset.
what i don't understand is that the new project works fine even tho the assembly file is still not in the obj folder
That tells you it doesn't need to be in the folder
well the error said that it has to be there
Thus why it's a bit important to understand what's definitely the problem to not create XY problem/solutions
yeah ik
Hopefully everything turns out fine/great
i wanna know what the problem is so that i get a little more familiar with unity...maybe
until now, yeah
ty all for helping me out
Hi im struggling to attach scripts to my game objects, it comes up with a message saying "Cant add script behaviour VisualContainerAsset. The script needs to derive from Monobehaviour!"
Does your VisualContainerAsset script derive from MonoBehaviour?
how do i check?
Open the script and look at it
That's not VisualContainerAsset
i have no idea what VisualContainerAsset is
You are trying to add it obviously. So it has to be in your workflow of trying to add a script to the GO somewhere
According to your error, that'd be the script you're trying to add to something
right but when i open the script, where do i see if it derives from MonoBehaviour?
So you have a file called TesterScript.cs ? And you add that to your gameobject from the project view?
Tester script.cs
It would have the words : MonoBehaviour near the top
That does not match VisualContainerAsset
And apparently there isn't any mono behavior classes in the file
your filename needs to equal your classname with no spaces, upper and lowercase etc
Maybe what you're looking at in your ide is something other than that file - maybe a cache due to name changes while the file was still open.
hey. can anyone help me with my pause menu and the buttons included. Everything should be working but i cant seem to find the issue with the buttons not actually being interactable. I just need a more experienced person to lookover it. thanks
This is my script.
Seems that your issue has nothing to do with the code and more with the UI being interacteable
Are these UI buttons?
Do you have an Event System in the scene?
@frigid sequoia@polar acorn Thank you. I'll send screenshots of my scene and the appropriate things included
{
float mouseY = Input.GetAxis("Mouse Y");
float newRotation = Mathf.Clamp(cannonPivot.localRotation.eulerAngles.y + mouseY, minYRotation, maxYRotation);
cannonPivot.localRotation = Quaternion.Euler(0f, newRotation, 0f);
}```
Im tryna have a simple script where a gameobject can only move on the Y axis and are limited by a min and max rotation float
Anyone know why its not rotating on the Y and also why when it hits 0 it just snaps back to the max rotation value
and then i have both buttons (on click has the representative stuff for the different buttons)
The last image makes it seem that you have no EventSystem; do you?
i do. sorry
Don't read the current rotation from the transform. Make newRotation a class field and add mouseY to that instead
{
float mouseY = Input.GetAxis("Mouse Y");
currentRotation += mouseY;
currentRotation = Mathf.Clamp(currentRotation, minYRotation, maxYRotation);
cannonPivot.localRotation = Quaternion.Euler(0f, currentRotation, 0f);
}```
Works! Great thanks
Not sure if this is what you meant directly but it defo works
So... your issue is that you cannot interact with anything in the UI? Even though they are marked as interacteble?
yep. so when i click on any button the menu doesnt go away nor does the actual function its meant to do happen
only when i press esc does it go away
Do you have a raycaster on your canvas? Do you have an image as last child in the hierarchy that is marked as raycast and blocks all raycasts?
Ι just tried importing Unity's Bolt and all I got was a bunch of ERRORS!
i have a graphic raycaster on my canvas
What version is your unity editor?
Then check against your hierarchy, if there is any image above that blocks it. You could hook into the eventsytem update to check, whats the last hit UI element too
I mean, if it doesn't work with 2021 "yet" it probably doesn't work with later versions.
Bolt no longer exists, it's been incorporated into Unity itself under the name Unity Visual Scripting.
https://unity.com/features/unity-visual-scripting
Why are you trying to open Unity 5?
this is my hierachy along with canvas
Maybe, this a stupid sugestion, but maybe it is not running cause the timeScale is 0? Can that be a thing?
So make it in an actual modern version
You can do that without a near decade old editor
Then we can't be bothered to help you goodbye
Well what you are attempting is not working....
ive checked and the exact same thing is working for others
<@&502884371011731486>
Whats in the last part of your UI hierarchy? Any image overlapping?
!warn 1135924484327616553 If you cannot be civil, then please leave.
plainrocky has been warned.
i dont believe there are any other images that are overlapping. i may be dumb though
I`d say, hook into the eventsystem updates and check what you are actually hitting
If you look at the bottom of the Event System inspector, there's a window that will show you what object you are hovering over. See if that object is what you expect
okay thank you. im new to all this stuff sorry. this what i see when i click on the 'button'
Doesn't look like anything's selected at all. Can you show the inspector for your canvas?
!ban save 1135924484327616553 Not mature enough to bother trying to correct their behaviour.
plainrocky was banned.
Hm, it has a raycaster, your button is interactable, nothing's blocking it, I'm not sure what else it could be
hmm thank you. im not sure what to do. ive tried everything
wait mate
what is this
hold on
its working but only when im in dialogue with my npc????
Looks like your code is blocking your system 😉
man...
void Start () {
float a = 8f;
float b = 6f;
int sum = (int)a + (int)b;
}
why is this not giving me a value in console? is it cast incorrectly?
did you log it?
u dont debug the sum ?
What should be putting it in the console
you can use print or Debug.Log
even though it is fixed now, I cannot see the list which I think is supposed to be shown there?
Are they public or serialized?
They WERE private and not serialized, which would of course not show in the inspector. Did you change that?
huh?
i got it working. I was over thinking it way to much
I think the way I'm doing my sprite movements is causing me to flip through my edge of map colliders
dont understand why my for loop is acting up all of a sudden
Not much we can do to help with just that
ill explain
Maybe show the code and describe what "acting up" means?
basically i have a burst gunner enemy that fires in bursts of 3
its functions based off a for loop
basically i define how many shots the enemy shoots out in an integer and get a for loop to generate an "enemy bullet" for each cycle
sounds reasonable so far. What makes you think the loop is "acting up"?
it stopped working suddenly
what does "stopped working" mean?
show the goods\
📃 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.
What do these logs say?
for (int i = 0; i < shotsfired; i++)
{
Debug.Log("shot" + i);
Debug.Log("shotcount"+shotsfired);```
what are they printing?
You're getting an error
68
Basically you're passing null in here audiosource.PlayOneShot(shootclip);
you're passsing in a null audio clip
Always fix any errors before worrying about anything else. Your for loop is irrelevant here, because it simply cannot complete due to the error
Which means you forgot to assign it in the inspector
I think this would be line 78 whereas he said his error was on line 68?
Help please
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
// Start is called before the first frame update
public float speed = 10;
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.LeftArrow)) { transform.position = new Vector3(-5f, transform.position.y, transform.position.z) += Time.deltaTime * speed; }
}
}
You are using find.
Would be better to do something else
You probably have another copy of this script where the clip is not assigned
Can you show a screenshot of the full error stack trace?
transform.position = new Vector3(-5f, transform.position.y, transform.position.z) += Time.deltaTime * speed;```
why did you write += here
instead of just +
Why is there a +=
Is this underlined in red in your IDE?
No
Then you need to configure your !ide
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
• Other/None
Then it is still unconfigured
You've been linked this guide a number of times
Stop everything and do it. It is a requirement to get help here
correct
You've got something strange going on therecs position = vector3 += float
You can't add a float to a vector
if (Input.GetKeyDown(KeyCode.LeftArrow)) { transform.position = new Vector3(-5f, transform.position.y, transform.position.z) + Time.deltaTime * speed; }
make it make sense
think about what it's doing
and make it make sense
Just red line
Ok, you said no red line earlier
Okay, so it is highlighted
There is wasn`t red line
Now you just need to make it mathematically sound. You can't add a float to a vector. What are you actually trying to do with this value?
Maybe you meant for speed to be a vector 3?
And to not use the += operator
You cannot add a float to a vector 3
Your offset needs to be a vector 3 as well - assuming that's what you're intending to do.
My assumption:cs position = modifiedPosition + offset
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
// Start is called before the first frame update
public float speed = 10f;
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.LeftArrow)) { transform.position += new Vector3(-1, 0, 0) * Time.deltaTime * speed; }
}
}
Where offset would be the speed vector scaled by delta time etc
I should have use *
It's * time. Deltatime
I did that
I feel like I came a bit. further
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
// Start is called before the first frame update
public float speed = 10f;
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.LeftArrow)) { transform.position += new Vector3(-1, transform.position.y, transform.position.z) * Time.deltaTime * speed; }
}
}
Because of +
Lol
🗿
Good thing u noticed I spent 2 hours fixing a + sign issue when I was making an inventory
🗿
How?
So there was one line when I was making the drag feature in inventory
It was smthing like
Recttransform.anchoredposition = eventdata. Delta
It was meant to be += eventdata.delta
And i just Couldnt see it
Doesn`t work
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
// Start is called before the first frame update
public float speed = 10f;
public float velocity = 10f;
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.LeftArrow)) { transform.position += new Vector3(-1, transform.position.y, transform.position.z) * Time.deltaTime * speed; }
if (Input.GetKeyDown(KeyCode.RightArrow)) { transform.position += new Vector3(1, transform.position.y, transform.position.z) * Time.deltaTime * speed; }
if (Input.GetKeyDown(KeyCode.UpArrow)) { transform.position += new Vector3(transform.position.x, 1, transform.position.z) * Time.deltaTime * velocity; }
}
}
That`s shoud work
Shit happens
None of this math makes sense. Why are you doubling the Y and Z position every time you tap left or right
What?
When you add a value to itself, what happens to that value
Use vector3.right and vector3.up firstly
Adding
So why are you also adding the current y and z position to the current y and z position while you're trying to change the x position?
🤷♂️
So if you don't know why you're doing it why did you do it
Calm down he is totally new
Code doesn't just happen, you were surely thinking of something when you wrote it
He's also been asking basic syntax questions and refusing to elaborate on any decisions for the past week
Week?
The person likely wantscs position += direction * speed * deltaTimewhere it would be the same ascs position = position + direction * speed * deltaTime
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
// Start is called before the first frame update
public float speed = 10f;
public float velocity = 10f;
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.LeftArrow)) { transform.position += Vector3.left * Time.deltaTime * speed; }
if (Input.GetKeyDown(KeyCode.RightArrow)) { transform.position += Vector3.right * Time.deltaTime * speed; }
if (Input.GetKeyDown(KeyCode.UpArrow)) { transform.position += Vector3.up * Time.deltaTime * velocity; }
}
}
I`m noob in Unity
🤷♂️
We all were and i still sm
But you're probably not a noob to math and logic
But don`t understand why Vector3.left and why not new Vector3 (1, 0,0)
Same thing
🗿
But u used transform. Position.y instead
Cus u used vector3(5f, transform. Position. Y, transform. Position. Z
If not longer
Btw are u just testing stuff or watching a tutorial
But this same thing
No it isn't
I`m taking position of object
This is the important stuff
1, 0, 0 and 1, position.y, position.z are not the same
Stop doing that
If u totally new to unity I suggest watching the Junior programmer tutorial on the learn.unity page
Because two things that are different are, in fact, different
I started from there
I literally cannot explain this any clearer
U will learn a lot from there
this is basic object permanence
I just thought logically, after all I saw in Unity learn that I can take there and change the coordinates I need without touching the other Y and Z, because it's like the same thing if I just write 0, 0. What would that be there are 0 and 0, that's right.
Again, when you add a value to itself, what happens
Do you get the same value back, or a different one
If you have two apples, and someone else gives you two more apples, how many apples do you have
I didn't understand the analogy, but thanks
If ur transform. Position is (5, 5,5) aand u do transform.position += new vector 3(transfrom.position.x, transform.position. T, transform. Position. Z)
Then u actually do
(5+5, 5+5, 5+5)
2+2
Pretend the object's y position is measured in apples
that's the analogy
10
If you add two apples to two apples, you no longer have only two apples
you have a different number
But i`m adding 0 + 0
Is it bad?
Now you are. Before you were adding position.y and position.z and that's why you were told to change it
and then you asked why it made a difference
and I'm trying to explain basic addition
I know
This
U aren't adding 0+0
U are adding the coordinates to itself or Mutliplying it by 2
What should i do?
To make the object move?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
// Start is called before the first frame update
public float speed = 10f;
public float velocity = 10f;
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetKey(KeyCode.LeftArrow)) { transform.position += Vector3.left * Time.deltaTime * speed; }
if (Input.GetKey(KeyCode.RightArrow)) { transform.position += Vector3.right * Time.deltaTime * speed; }
if (Input.GetKey(KeyCode.UpArrow)) { transform.position += Vector3.up * Time.deltaTime * velocity; }
}
}
There`s too * coordinates
Yes
I did that
Yes, now your object will properly move speed units per second for one frame every time you tap the left or right key
Use transform. Translate
If(input.getkey(keycode.W))
{
Transform.Translate(vector3.right*time.deltatime * speed
}
Hello all, question regarding cameras and netcode - when i add a new client, the camera from the previous client switches to the camera of the new client... any idea how to fix this?
To make it jump u can maybe add Rigidbody and use the addforce option
You can jump with translate. Adding a rigidboyd would mean they should change all their code to rigidbody based
Transform.Translate(new Vector3(1, 0, 0) * Time.deltaTime * speed) is better
You don't want to mix
Thanks
Absolutely same but yea if u think it's better sure. U need to understand
I understand
just be aware Translation = no collisions
That's why I said maybe I never worked with translate only used player controller and I'm not that good either
Transform too?
well moving Transforms directly is what translation does, and it same as teleporting
it doesn't respect the physics scene
yeah for teleporting assigning position is more than enough, no need for translate
Then why was it added?
to simplify movement with a few extra options like relative coordinate space etc.
but all its really doing is position +=
this is the function behind Translate
nothing fancy
For when it makes sense to do that. Not everything needs collisions
And not everything that moves is a player or enemy or something
And sometimes you DO just want to teleport something
Ok, thanks
Lock door portal
what's an event system? I randomly found this on my hierarchy
For UI
Makes interactable UI elements (buttons, input fields) work
It is created automatically when you create a UI element. Do not remove it
I'm created
Really automatically?
Yes.
#💻┃code-beginner message made this one if anyone can help me out or not
The options are, there was a bug and it didn't get created. You deleted the one that was automatically created. You currently have two
No, really doesn't created
im just following a course and a random error has popped up with cinemachine
and im not sure why
If you have one already it doesn't get created
If you have ui in the scene already, it doesn't get created
Don't have
this is supposed to check if any of the equipmentCells item is not null
if((item as EquipmentItem).equipmentCells.Any(equipment => equipment.cell.item != null))
it doesnt work
even though theres clearly an item in at least one of them
i mean i could do this
but i was trying to simplify it
not having the loop
When dealing with a Linq query doing what you don't expect, usually it's a good idea to first make it the brute force way and make sure your logic works. Try storing equipmentCells in a list, loop over it, and check each item. If that works, then the issue is the Linq query itself
Okay, so this works, but your Linq query doesn't?
wait it also doesnt work
hold on
im so dumb
i was doing equipment.cell.item instead of equipment.item
whats the simplest way to access a textmeshpro UI
public TMP_Text tmpText;
thanks
It's a component like any other.
is this valid
It will compile definitely. Depending on what p1Balance is, it may or may not be what you want.
might need some formatting depending on what it is
what do you mean by "not getting the variable" and also how have you verified that it isn't
i have verified as I was logging it and it wasnt updating
whereas the original variable in the other script was updating
it sounds like you need to learn the difference between value types and reference types
does it need to be public?
mate you haven't even properly described what you mean when you say it "isn't getting the variable". but also if this is in fact an issue of not understanding reference types versus value types, then the access modifier is entirely irrelevant
public/private/internal changes what classes are allowed to call that function or access that variable
i am getting the variable woodnumber from the script spawnwood which has a variable called woodnumber
i know that
but i dont know why its not working
and . . .?
is that not a good explanation
that isn't an explanation of what you think isn't working at all
the original woodnumber variable is updating in the original script
no
Updating would likely have to happen in Update
No you're getting it in Start
are you expecting the woodNumber variable to stay the same as the SpawnWood component's woodNumber variable? if so, then i will reiterate that you need to go learn the difference between value types and reference types
There's no good reason to have a duplicate variable of a variable in another script like this
Just read it directly from the reference to the other script
Otherwise you get this annoying headache of keeping them in sync
Yeah, so simply say SpawnWood.woodNumber instead of the variable you made
Maybe, but int is a value type. You’d have to do some super uneccessary stuff for that to work
It’s easier just to say SpawnWood.woodNumber
on a similar note, I have a UI used to modify a data structure with an input field. I’m having a bit of challenge trying to figure out how to properly keep them synced, to make the data match the UI and visa versa. Because it feels like methods that do one change should call methods to sync UI to/from data. Is there a simple way to organize without getting confused?
how would you go about only subtracting when thewoodnumber changes. i know this is simple but the only way I can think of doing it (coding everything in one script) will make things messy
Right now it subtracts every frame (as expected)
like, I have a method that writes current contents of data structure to imput field. I have another method that writes contents of input field to data structure. And when I do other things, I am getting confused to keep them in sync.
Put that line of code in a method, call that method every time you change woodNumber
this might sound stupid, but how would I detect when it changes
When you code it to change
would I need to use another variable to save it's previous number
When you make the value change via code
No, every time you set the variable to something else, call the method
Do what in one code?
im changing the variable in another code
i didnt know i could do that
Yes, in the same way you would reference the variable
If the method is static, yes
It seems like you need to learn some c# basics. I wouldn’t reccomend doing unity until you have a solid c# foundation
And google should be plenty to answer your question
short timeline + inexperience = bad game
no offense
i was already working on it for a week a few months back
it's nearly finished so im not too worried about that
that does not fill me with confidence
it's just that i was learning on the go
Learning on the go is fine, but things like what static means are basic concepts you need to know before you start developing in unity
you are driving without a license, then worrying you are going to miss your flight if you don’t gun it
Anyway, I have to go, good luck, hope you get this figured out
i used gemini ai and i still have a vague idea
does it just mean there are no more than one of the same name in the script
Static means they belong to the class, not any instances of the class
i know what an instance is and the class is the script itself right?
but how could the script have instances
you are (likely) confusing the concept of an instance with the property name commonly used in the singleton pattern
A script is a blueprint for how to make a thing. An instance is that thing.
A script is like, the DNA genome of a cat. An instance is an actual Cat
so whats an example of a static function
everything on the Mathf struct
Something that does not need any specific instances of a thing
Getting the absolute value of a number does not require a specific "thing" to do the math. You just pass it a number and it gives you a result
when would a function not be static
When it is done by a specific thing
so your saying it shouldn't require parameters?
parameters have nothing to do with anything
In this example, something static could be the total number of cats currently on earth
And something non static would be what color the cat is, bc that can vary from cat to cat (instance to instance)
A static function does not require any specific thing to exist.
A non-static function requires the thing it's defined on to exist.
You don't need to know about any specific cat to answer the question "Are cats mammals?"
But you do need to know about a specific cat to answer the question "What color is a cat?"
i get what your trying to say but I dont get how that applies to functions
does that mean as long as the function is fully executable and all the pieces needed for it to fully function are in place it is static?
ReturnColor of the cat couldn't be static
ReturnDefaultLimbCount could be
I was able to make a path generator along a generated tile map but can anyone explain how to make it procedural and not directly from the start to end point?
A static function does not have pieces
it simply exists
It is a procedure that can be done regardless of any instances of any classes
oh okay so my function that i need isn't static then
https://docs.unity3d.com/ScriptReference/TrailRenderer.Clear.html
Clear the trail renderer after you set the player's start position
like this
{
StartCoroutine(Respawn(1f));
}
IEnumerator Respawn(float duration)
{
tr.Clear();
rb.simulated = false;
rb.velocity = new Vector2(0,0);
transform.localScale = new Vector3(0,0,0);
yield return new WaitForSeconds(duration);
transform.position = startPos;
transform.localScale = new Vector3(0.22f,0.22f,0.22f);
rb.simulated = true;
}```
As your path is going, pick a random adjacent tile that does not already have a path on it, you should eventually reach the destination. There are many maze generation algorithms that have different conditions and come up with different kinds of results
after
alright
I remember having to do this to get the renderer to actually clear it properly #💻┃unity-talk message maybe they fixed it since then 
Yes, that's why I said to clear the trail renderer after you set the player's location
Where did you put it?
i did that but its not working
{
rb.simulated = false;
rb.velocity = new Vector2(0,0);
transform.localScale = new Vector3(0,0,0);
yield return new WaitForSeconds(duration);
tr.Clear();
transform.position = startPos;
transform.localScale = new Vector3(0.22f,0.22f,0.22f);
rb.simulated = true;
}```
after
alr
{
rb.simulated = false;
rb.velocity = new Vector2(0,0);
transform.localScale = new Vector3(0,0,0);
yield return new WaitForSeconds(duration);
transform.position = startPos;
transform.localScale = new Vector3(0.22f,0.22f,0.22f);
rb.simulated = true;
tr.Clear();
}```
like this ?
Yes, try that
it worked, thanks
Hi, I'm having an issue where the game does decrease the enemy's health as it's supposed to, yet value of the slider doesn't change meaning that it doesn't move?
As you can see the HP value has decreased yet the bar itself hasn't moved at all, have I missed something?
your slider component is not setup properly
Ahhh no wonder
your bar looks green bc you have an image component, the slider component is not what is controlling the color rn
Do I have to include the slider.MaxValue along with the value?
your code is fine
mb sent that just as u sent that message lol
Ok so its the actual slider itself that's the issue, so the slider IS decreasing but the green isbecause of the image itself?
how can I make sure it does decrease accordingly
no, you do not need the image at all. the slider should be the only thing you have. however, your slider component is not setup for it to show anything
Ok I'll get rid of the image
your component should look something like this
Ah ok
if you rmb and reset it will do this automatically
ok now it looks like this
now assign fill rect and handle rect
sorry im not sure what exactly to assign it to in this case
create a new slider gameobj and delete your current one
that'll assign them automatically
ok
Done it, I'm trying to adjust the shape so its rectangular but im not sure how to
How do I make this rectangular? 💀
ok
u can use an empty image to get a perfect square
rectangles are not squares 😵💫
All squares are rectangles, but not all rectangles are squares
anywho..
is there a way to make the pixel perfect camera follow the player without cinemachine ?
huh? they're not related
Bro what do I even do with all of these different components 💀
can I get rid of some of them
lol. theres some of em that are not really needed yea
what are you trying to do?
I just wanna create a sliding health bar man
the code's ready its literally just creating the slider
use an Image component set to Fill
its supposed to go on top ofthis
much easier and better than a slider
read the name of the objs in the hierarchy
these two objects are the important ones
and ofc the main slider component.. but yea image and fill's work great too
yea you'll get a much better result with Image component than slider
aight
You'll need something like this
download it put it in the image component set the mode to Fil
Cause I genuinely tried using a bar image and adding the slider component but that didn't work either
Bro scroll up I tried with my code and it didn't work
is there a difference between destroying an object or turning it's setactive to false
I couldn't add a fill and handle rect to the image lol
in terms of processing
disabling doesn't destroy the object
both are pretty much already in memory, destroying will eventually free it up
does anything to do with it run still
Yes? They are significantly different
not unity events
Only Update and other unity methods will stop
All your own methods will operate as normal
You can still call functions on disabled objects if you have references to those scripts
ohh okay
and if it were just a sprite for example
would it be fine if it were setactive false
Why would it not be fine?
We don't know what you want to happen
if it still were using cpu power
you're overthinking this
probably
how 
It would consume space in ram still. But whatever
bro im so cooked
cause in my script the sprite updates to the mouses position
so if its setactive is false would it still be moving to the mouse but invisibly
but yeah it doesnt really matter
how does a sprite update a position ? 
transform.position
updates it's position to the mouse
whats that got to do with a sprite
it's following the mouse
is there a way to make the pixel perfect camera follow the player without cinemachine ?
is there any way to make the composite collider's collision edges thicker when using polygons geometry type instead of edges? My enemies can slip through the thin edges
not a code question. Also answered this already
Same way as a normal camera
is this even an answer ?
Yes. With the 0 details you gave, we can't answer any more
the pixel perfect can function perfectly fine without cinemachine..
How do you want it to move, what should it follow, what axes do you move in?
There are tons of guides on how to have cameras follow things
i meant to follow the player...
Ok, 1 out of 3. Good good. Can we get the rest?
i tried but that didnt work
show what you tried, and be more clear what didn't work
alright
i'v added this script to the camera to make the camera follow the player but its not working with the pixel pefect
{
private Vector3 offset = new Vector3(0f, 0f, -10f);
public float smoothTime = 0.25f;
private Vector3 velocity = Vector3.zero;
[SerializeField] private Transform target;
private void Update()
{
Vector3 targetPosition = target.position + offset;
transform.position = Vector3.SmoothDamp(transform.position, targetPosition, ref velocity, smoothTime);
}
}```
you put this on camera and pixel pefect is on the camera?
yes
i dont know but ya makin me feel dumb..
How? We need information to help.
show the console during playmode
make sure there are no erros, also it should prob be inside LateUpdate for any cameras
or it will be chop
Bro im still stuck on making this damn slider the size I want it to be
wait
i think the prob is that i hav a animator on the cam right ?
@rich adder Ik its bad man
Is the animator affecting the transform?
Could be the issue
why didn't you just use the Image component like suggested
What is the purpose of the animator there?
yep alright i found the error
Noice. Good job
i just forgot that i've got an animator on the camera
ok good, you need a sprite inside to "unlock" the Fill mode
^ add that as ur sprite and ur "Fill" option will reveal itself
looks like a circle until u click it 😄
wish unity didn't make the built in square sprite a myster asset..
haha yeah gotta love discord rounding
sprite has been added
Image Type
O DAMN ITWORKS
and then u have a .fillAmount variable u can use to update ur health/shield or w/e
you can even do rounded ones
imma look up some examples cause im notsure how to use it properly
gray = unused
ah so it should be fine
wb white
the opposite lol
so its used
Discord embedding making you look insane
what is real anymore
ah shit, my square is circle too!
idk why i used 15x15..
trying to split pixels i guess
prob min is 16 
idk assuming they love doing multiples of 2
ya, thats where my 15 pixel block is gonna look faded on one side
IT WORKS OMG
hellz ya
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Line : MonoBehaviour
{
public Transform pos1;
public Transform pos2;
public LineRenderer line;
// Start is called before the first frame update
void Start()
{
line.positionCount = 2;
}
// Update is called once per frame
void Update()
{
line.SetPosition(0, pos1.position);
line.SetPosition(1, pos2.position);
}
}
I am new to Unity.This is my first script and i have no idea why it doesn't works
What isn't working
this has me so confused. I ahve this code that makes it so when the player touches it, it moves the camera and changes some other stuff. and it works great. the on screenshot with NewCam2 it works flawlessly. but on the screenshot with newcam3, it works but all the enemies become invisible. I can still interact with them, but they are just... invisible. why????
Ill provide any other info needed
when i asign every component(idk how to call them) nothing happens
Are they at a different Z position
the newCams?
Show the inspector of this component
Yes
Okay, and what happens when you run the game? Send a screenshot of it then
I'm guessing your code moves the camera to the position of newCamX, and depending on your culling distances, moving the camera to a different Z position might mean some things are outside of your culling range that weren't before
It works ig but not in the inspector
Why would it work in the inspector?
Again, why would it work in the editor?
Your script doesn't do anything in the editor
There's a checkmark in the material settings. Make a material that's not two-sided
why bro doesnt wanna let me touch his x and y?
it is indeed a vector2
https://gdl.space/rekenufiqi.cs full script js in case
you're trying to use the movement variable . . .
you're image doesn't show that variable . . .
oh woops
nvm i was suppsoed to use direction not movement
confused myself with variable naming
!ban 971172399015940166 ignoring warnings
sevenenty7. was banned.
should i calculate force using f = ma for a projectile
or is there a better way for unity
(2D)
AddForce is a thing
life changer
thanks
does that add force though or also calculates it?
i need a magnitude of the force
and it should be dependant on an already set motion that i have
It actually adds the force
https://docs.unity3d.com/ScriptReference/Rigidbody2D.AddForce.html
It is common to use the difference between the current speed and desiredMax speed
Depends on what you want to do with it
wait so how do I get the force magnitude?
Do i need to recode my projectile to use addforce
rigidbody.velocity
but isn't acceleration for force
Depends on how it is coded now
What acceleration, and what do you mean?
Velocity is a speed and not an acceleration
(m/s vs m/s^2)
force = mass x acceleration
i need the force
AddForce does that
You plug in a vector and it applies force to the rigidbody
okay ill try and see how it works
That is it
but sorry to clarify can i also return the force magnitude value from the addforce thing?
AddForce will not work if you set velocity directly like that
How can I annotate a field's type as being a literal class rather than an instance of the class?
class Bar { }
class Foo {
public ? bar;
Foo(? bar) {
this.bar = bar
}
}
// I don't want:
Foo f = new Foo(new Bar())
// I want:
Foo f = new Foo(Bar)
No, you would have to read velocity from the rigidbody
but i need force not velocity
Why?
You would have to calculate it I guess then
cause i will have breakable objects which are destroyed when the force of the projectile on collision is great enough to destroy the object
AddForce does not calculate a force needed to get from one position to another. it applies the amount of force you tell it to apply to the rigidbody
my rigidbody already has a projectile function
I just need to take the force from it now
You can calculate force from velocity and mass
What would you call the velocity at one point and then the velocity at another point?
what do you mean?
F = ma is more about finding the force enacting on one object, not collisions necessarily
I mean that caching the velicity at one point and then caching a second velocity will give you acceleration
That SHOULD work, I was more thinking f = m * v / t
But now that you say it, t is probably not super helpful in unity. Or at least can be ignored?
I dunno. Not something I have ever done. Just remembering physics class
I think you're talking about generics
I want to do runtime stuff with the classes
Mmm foobars
https://learn.microsoft.com/en-us/dotnet/api/system.type?view=net-8.0
Maybe can use type?
Hey, I'm working on this project for a while but I just realised something is wrong with my player controller. Any tips?
Aghhh I got the same input from my friend too.. How can I change it?
Then Theres probably a better way to implement whatever you are trying to implement but you're basically describing reflection (i don't recommend doing any reflection except if you're doing some kind of meta-programming)
I changed it to pivot, the problem still persist. Thanks for the input though!
changing input alone isn't enough..
there is like a second part to that
I have a function that is going to receive a list of objects and then iterate through them, selectively do stuff based on if the object has a property of a certain type. like, an entity component system. a System iterates through all entities, and only processes the entities who have components of specified types.
Hey so I have a bool that tells whether something can move up, down, left, and right. Any idea how I can get it to randomly choose one?
Got it! I solved it by changing the location of the player controller. Thank you so much for the tips
random int between 1..4. index into list of directions
Oh thats it...
Just search getType() c#
You can use this method to figure out the type of an object in runtime
yes but I need to compare it to a specified type
if getType == x
x needs to be the class