#💻┃code-beginner
1 messages · Page 192 of 1
Can it run 100 m race in 10 seconds?
Can it leap tall buildings with a single bound?
ryzen 3 2200g
jesus
8gb
dont expect stellar speeds with such a mediocre cpu
1tb HDD
not even SSD ?
not where I'm saving my project
smart
that will slow things down a fair bit
I have a ryzen 7 1700x and Im barely hanging on, there is no way your CPU can handle much better anyway
ryzen 3 is low level tier
also, what do you mean by "busy"?
If you're talking about the popup after changing your scripts, Unity has to recompile all of your code when you edit it
yeah now imagine that on a mechanical drive
Oh no correction I didn't express myself well, little lapsus, I meant between transform.position.y and transform2.position.x So it'd be the global Srt(x^2 + y^2) formula, and I'm searching a method. Or I guess I'd use Vector2.Distance(Vect3(0, transform.position.y, 0), Vect3(transform2.position.x, 0, 0)) ?
then you wonder why it takes long lol
also my gpu is a GTX 660
Speaking of which, is there a way to disable auto recompile? 
You can set unity to only refresh on command
gpu means nothing for script compilations and CPU bound actions, they need brain power
Oh really? Where's that setting? I must have missed it
Auto Refresh in the Asset Pipeline section of your preferences
(not project settings)
Ohhhhh, I see I'm not the only one who hates auto refresh 
I know it says they're going to different numbers
If still auto reloads on play and build right?
No. It reloads when you tell it to.
the numbers are correct
ctrl-R
how do i remove this line in the middle
Oof 
Oh, that's the suggested maximum line length
It's going to be 80 or 120 characters or something
show me where you call ReturnToMenu
I don't know exactly where to toggle that
why when i Instantiate prefab collider and my script components are off?
You tried rsetting layout like I suggested before?
private void OnCollisionEnter2D(Collision2D collision)
{
if (collision.gameObject.TryGetComponent(out Mergeable idfk))
{
if (idfk.level == level)
{
rollMeRand();
if (idfk.rand > rand)
{
if (nextBall != null)
{
GameObject B = Instantiate(nextBall);
B.transform.position = transform.position;
}
Destroy(gameObject);
}
else if (idfk.level == level) Destroy(gameObject);
else Destroy(gameObject);
}
}
}
public void rollMeRand()
{
rand = Random.Range(1, 1000);
}```
many times
interesting... I never seen that line beofore, trying to find out what it is
wdym by "my script components are off"?
ther are disabled
English
I'm not sure how to disable it in the mac visual studio though
Are they disabled in the prefab?
no
You sure? Show some screenshots
Ahh yes I have it too
A component will disable itself if it throws an exception in Awake or Start
(i think both?)
ok and now.. on the instantiated prefab?
yes
I mean show a screenshot
ReturnToMenu()
so how do i remove it
I always kinda ignored it lmao I never figured out how to get rid of it..
Can you not crop the screenshots? Just show the full unity window
because it's unclear which object is selected here
lemme record
this thing is actually driving me insane like i can not do this
I posted it on r/unity and somebody commented this
At a first glance, in your LoadSite method, it looks like you're setting the selected site to active, but you're never disabling the others. So if the first one that loads is in front of the others, it seems like you'll never be able to see them since the first one will be covering them up.
And then like another commenter pointed out, in the menu method, you've got the for loop to disable all three sites, but you're passing in 1 as the index instead of 'i', which will always just disable only the one site.
r/Unity is useless
oh is it?
Why are there bears in the scene at the start?
yes because you should still be able to see 1 of these Enabled
in vscode 5 seconds after opening all the code turns the same color and gives me an error "Project system initialization finished. 0 project(s) are loaded, and 1 failed to load."
I think your problem might actually be ReturnToMenu() unless you can show me its fine,
im trying to make merging game, one of them dont have prefab in nextBall
The prefabs should not be in the scene at the start
those aren't prefabs
prefabs are the things in your project folder
You should have a separate script that instantiates things
oh ok...
hey guys. why these brushes dont work? i click on them, but my mouse cursor doesnt change. any help?
so its working
#⛰️┃terrain-3d - not a code question
for the fist photo but when I click the second button it highlights site snow2 but goes to the first photo
wdym "goes to the first photo"
screenshot sitesnow 2 active in scene
There should be 3 separate photos one for each button but it keeps going to the first photo not photo 2 when I click button two and not photo 3 when I click button 3
I get what ur trying to do but we saw the Debug.Log is printing correct index, so you have to show what happens when you click button #2 and which object goes Active
So the code is working
you just put the same picture for Site Snow 2
this whole time

Got trolled hard
yep, same material
ok all three objects are being toggled correctly you just got the same material/texture
they are not supposed to be the same photo
are you forreal?
Then don't use the same photo
Computers only do what YOU tell them to do
they show the exact same photo
And you told it to use the same photo
because you put the samee tetxure.
Yes, that is what you did
yes, because you told them to
ok then where did I go wrong?
Forreal? You used the same photo!
now we're getting somewere
you cannot use the same material with same texture across 3 objects and expect to be "different photos"
that makes no sense
mehh at least the code was working
I am using the following line to create a Vertex.
Vertex v = Instantiate(Resources.Load("Prefabs\\VertexPrefab"), pos, Quaternion.identity) as Vertex;
This compiles fine, but throws a runtime error. For some reason, v is null.
Any idea why? If so, you you explain what the line is doing so I can understand?
Thanks.
who told you to make the path \\
isn’t that backwards
That's the only way it escapes the escape character. It worked when I was casting it as a GameObject.
That path seems to work fine
Yes
Why would you want to escape it? It is necessary
The path is wrong. Nav just linked the docs
its fine , it isnt relevant now, we already found the cause. The code was never a problem
ok how do I fix the material being wrong?
Just. Put. Different "photos" for different spheres.
Instead of the same one.
I would have to make 3 different spheres?
You HAVE three different spheres
And yes, of course you do
Just like the tutorial did
just apply the material to them if you have the spheres already
can someone help? I cant figure out how to spawn one, cuz when 2 objects collide the both try to spawn a new one
What is "one"
The path was fine. I am still getting the runtime. Here is the entire method.
Vertex v = Instantiate(Resources.Load("Prefabs/VertexPrefab"), pos, Quaternion.identity) as Vertex;
//Vertex v = g as Vertex;
Debug.Log($"Vertex is null: {v == null}");
v.setCamera(c);
return v;
}```
another prefab, i need only one to spawn
The path was not fine. But now there is a different issue
Ok, show the !code
!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.
I used that exact path many times and it successfully loads the resource, the problem is the same.
📃 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.
obj: https://hatebin.com/zcamyoujqq
manager: https://hatebin.com/gizzowahiu
You're using the non-generic version of Resources.Load
I presume you're getting a reference to the game object
You can't cast that to a Vertex.
If you want a Vertex reference, then ask for one
Resources.Load<Vertex>(...)
Will that still instantiate the object?
are they not different photos
Yes.
If you Instantiate a component, the entire game object is copied
You receive a reference to whatever it is you instantiated.
GameObject can't possibly cast to Vertex
yes but you applied the same material to all 3
Jesus fucking christ
A game object with a Vertex component on it isn't a Vertex
It's just a game object that has a Vertex on it
My character Controller is coliding with triggers, how do I stop this from happening?
Thanks. I didn't know Load could be given a class.
It isn't. Those must not be trigger colliders.
raycast?
it's similar to how there's a non-generic version of GetComponent (you pass it a Type instead)
currently using this to see if the character is groudned
Both non-generic methods just return a UnityEngine.Object
OK how come when I select a different image for the material for a site it adds it to all three sites?
The generic methods let you get a specific type right off the bat
yes, because you applied the same material to all three renderers
so of course all three renderers look the same
don't do that
Those are the different materials. Now look at the different snow sites and see which material is applied to each
make new layer and make script ignore it
If you have the same FBX changing one will change all of them
you have to Unpack the FBX
apply new material, then do the next
or just drag the material in to each instance
thanks
that'll work just fine
okay, so this isn't a CharacterController
FBX?
int layerToIgnore = LayerMask.GetMask("NotGround", "Player", "Ignore Raycast"); int layerMask = ~layerToIgnore;
Have the ball REQUEST a new ball from somewhere, not create the new one itself
Then you can control how many are created
I would suggest two things:
- Specify which layers to hit, as shown above
- Use
QueryTriggerInteraction.Ignoreto ignore all triggers
Your issue is assuming that this problem must be more complicated than it is because you don't think anyone would make such an obvious mistake and not check after three straight days of debugging. But I think you're giving them too much credit
ok thx
nailed it 😆
These three objects are instances of the same prefab.
If you assign a material to the prefab in the inspector, all three will get the same material.
Do not do that. Assign a material to each object in the scene, individually.
or assign the material to the prefab, so everything tied to the prefab will get that material
that's the exact problem
the three objects are supposed to have three different materials on them
they don't. they have the same material
prefab?
you see how the name of the gameobject is blue
please just do what I asked you to do
it sounds like you have basically no idea what any of these words mean. you desperately need to learn how Unity works before you try to make something in it
what do you mean object sites or buttons?
Every time you hear a new word. You repeat it with a question mark. Please TRY to learn for yourself every once in a while. Google "unity prefab" see what it means
Hello, I don't know why this script doesn't work. I know it gets the target position right, but doesn't add the force.
Also, PLEASE stop your project and go through the "unity essentials" pathway here
!learn
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
it’s tied to a stock gameobject file, called a prefab
so if you make edits to the prefab, it will connect the changes
AddForce doesn't take a position
It takes a directional vector
if you do not want this to be the case, you should unlink the gameobject in the scene from the prefab
you will know an object is linked when name is blue, and not linked when name is white
Yes, see how that says m_newForce?
Oh, it's gone
yea
Stop. Stop everything. You need to learn literally anything about the program you are using. !learn
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
Then you can normalize that and multiply it by a force if you want
thx
Do not attempt to work on this project any further until you at least know what the program you are using even does
Im trying to make ship rotate 180 degrees in y axis if its z position is less than 200 and start going +z in position instead of going - as in (0, 0, -1)
problem: its position in z wont change at all
what Ive tried: put if statement in different places in update
changed private bool shiprotate to true and false
did u try putting a - in front of rotationSpeed? then it should go -z instead of +z right?
I don't know what I did but it works now
No,its the muzzle from the gun where it shoots the bullet
rotationspeed is nothing to do with its position
it only rotates the ship in z axis continously
put a - in front of Vector3.forward actually
did u try that
"transform.position = transform.position + new Vector3(0, 0, -1 * seperationSpeed * Time.deltaTime);
transform.Rotate(Vector3.forward, rotationSpeed * Time.deltaTime, Space.Self);"
these lines work as intended
problem is in if statement
but let me try
in if statement you got a 1 * separationSpeed, try doing -1 * separationSpeed
wait thats position not rotation
And we know what you did, you added the right materials to the different spheres
Yeah you dont know, its not the fact we've been telling you what to fix XD
ship is supposed to rotate and come back if its z value is lower than 200 at the oppsoite z position
In if statement (0,0 "-1") I already set Z to negative value
and in regular update it is positive 1
shouldnt u rotate it by -Vector3.forward then in the if statement? if the other one has Vector3.forward. then it rotates in the opposite direction
wait also currently if it completes the if statement it also does the other one. is that intended? should it be if else
I will try to break it down:
" transform.position = transform.position + new Vector3(0, 0, -1 * seperationSpeed * Time.deltaTime);":
here. the ship goes in negative Z direction continously
" transform.Rotate(Vector3.forward, rotationSpeed * Time.deltaTime, Space.Self)" this is not related to position so im skipping it.
if (transform.position.z < 200 && !shipRotate180)
{
transform.Rotate(Vector3.up, 180f, Space.Self);
shipRotate180 = true;
transform.position = transform.position + new Vector3(0, 0, 1 * -seperationSpeed * Time.deltaTime);
}
here. if ships Z value is less than 200 its supposed to rotate 180 degrees then move in the +Z direction now instead of the regular -Z
this is actually my first time using if statements in C hashtag
It's called "C Sharp"
C hashtag
tell me you're zoomie without telling me ur zoomie
Ahhh you re talking about instead of 0.5,0.5 I replace it by the bulletspawn pos xd
John do you want me to record a video and tell what Im trying to achieve?
Yo Im confused, if you return a method, would the returned method run?
Whats wrong in this code? Like, the Menu is still visible when I run the scene.
And nothing happens when i press ESC
nvm I'm slow
because you never specified what happens when Pausa == true
Ah, it's the rigidbody. You need to either drag in the rigidbody component via the inspector (which you cannot, because it is private)
Or call GetComponent<Rigidbidy>() in awake
Yo Im confused, if you return a method, would the returned method run?
no
You have it, but it is not referenced. Simply having it does nothing.
Also, you need the type to be Rigidbody2D, not just Rigidbody
what are u trying to do
I have a method for a script and it says there is an error that not all paths return a value (I used an if statement with no else) so i said else return GetMethod(); incase there is an error
To clarify, it doesn't know WHICH rigidbody you want to add force to. There are times you want to add force to rigidbodys on different objects.
The compiler will rarely ASSUME anything, so it will NOT assume the rigidbody you're talking about is the one in that screenshot. You need to explicitly tell it that
why whats the original return type/
so just return null
cool
You're not "returning a method", you're returning the return value that comes with calling this method
I have no idea what that means lol😭
how can you return the return value
What would be the return value?
also this would be like 2 lines with an Array..
None of my code is efficient
I can tell lol
should learn about arrays
they are vital in coding
I dont cover basic coding 🙂
I expect my watchers to have somewhat understanding of c#
Aww you should teach a beginner sometime, I heard teaching is a form of learning in itself
Just like einstein said, if you cant explain it simply, you failed to understand
Its fun, I probably would do something later down the line
Think of a method call as simply moving to a different spot. It is no different than having the body of the method right where you call it.
public void Start() {
bool something = MyMethod()
}
public bool MyMethod() {
return true;
}
Is the same as
public void Start() {
bool something = true;
}
The return just tells it to put the value where the method call is
I dont have the "teacher" personality
Let me know, Ill be your first supporter
thanks!
You should follow a C# course then first before trying to learn Unity, basics are important, read about functions and recursion (arrays as well, everything basically)
Hah i get you especially when they fail to understand the first time, youll get used to it though
OHHHHHH I get it
Thanks for explaining
But would that also work for game objects?
Bro I need to learn unity now because I have an assignment to make a game in unity and its due end of this month soooo....
Oof
Fair enough
a month is a decent amount of time to learn some basics lol
I got other classes as well untop of this
It works for any type you can imagine
Wait so i can store a gameobject in a variable??
Omds
I realised i could have done this so much easier
You can store any type in a variable.
A gameObject is just a class
I will say that I almost never find myself wanting to store a gameobject, and I prefer storing COMPONENTS like scripts of rigidbodies and stuff
Because all of that can access their attached gameobject with the .gameObject property
Yeah, learning some C# basics would be probably a good idea if you just came to this realisation..
int armyNumber = (int)units[i].UnitArmy;
turnOrderUIData[i].unitArmyText.text = $"{armyNumber}";
Debug.Log(armyNumber);
public enum UnitArmy
{
ArmyOne = 1,
ArmyTwo = 2
}
How come, the debug log prints 0 and 1 only, instead of 1 and 2?
Where can i watch a VIDEO, i suck at reading
I know, reading is scary, but most of the good learning materials are in text form 👻
As for anything else, just google it I guess, there are tons of videos covering various topics
Cool cool
Didnt expect people here to be so nice
hi, im making a tower defense game. i wanted to make something where whenever you select a tower to build, an objects spawns with the icon of the tower u are currently trying to buil to inicate to the player what they pressed.
buildmanager:
https://hatebin.com/ahszcovimb
shop:
https://hatebin.com/zdcafhfplc
How do you guys learn game mathematics and apply that into a game engine? (I'm very new to this)
now how would I share this virtual tour?
!screenshots
No
Be mindful, if someone requests your code as text, don't send a screenshot!
!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.
ehh long code should be shared via links
first 2 if and else statements work as intended.
i made it
im basically trying to do the opposite in other 2 ifs and 1 else
starting at line 31
problem is: ship wont start moving in z direction
so many magic numbers here
what is supposed to be happening , I cant even tell
so first 2 ifs and 1 else work
when ships z position is less than 200 it rotates 180 degreees and starts going in positive z direction
and whats supposed to happen after that is if ships z direction is greater than 800
it rotates again and its z position goes down
thats all
like what happens in the beginning
Do I need to add my script to a gameobject for it to work?
ok ok thanks
debug your values to make sure they are what you think they are
What's the error say?
is the function static? otherwise you cannot call it directly from Class like that
Classes are just blueprints to an object
It is public
No static
You've got to reference an instance and call the method of an instance - not the type.
public GenerateOne generateScript
generateScript.PickAOne()
okay. so is everything okay with if and elses?
Ohhh i see
thats why I suggested you debug your values , like transform.position.z
!shipRotate180
You seem like a pretty good teacher already, why not start the yt tutorials?
Depends if you mean "apply that into a game engine" as literally using math when programming a game engine itself or using a game engine to make a game.
Generally - university and research. But if it's the latter then it shouldn't be necessary for most of the simple stuff. If you're good at basic math, vectors, etc, then you shouldn't have too many problems
Oh thanks thats kind
I try but I have 2 fulltime jobs , I haven't had the time to dedicate to it :\
TWO!!! How are both fulltime??
one is 10 hour shift for 4 days and 2 days are busy weekend job (bar)
thanks! hopefully will make this my job at some point and not deal with drunktards xD
Can anyone help with this? It should be working, in a different game it works and in a tutorial too
Loll have you seen a bar fight yet?
plenty 
static means it accessible everywhere, and only 1 exists of this item
And if someone asking, the buttons are not done yet
this is setting it to Active = true
is that intended
No
Like, its a normal Pause Menu, but the for the guy in the tutorial it works perfectly
ohh, well the menu is being turned to active if ESC runs
can u show the tutorial?
its completely in spanish
or u askin for ss?
May be blind or sum but i think its the same
but is the menu starting with it OFF?
Escape causes the editor to unfocus, try a different key. Other than that, to verify if the key is at fault, place a log inside and see if anything prints.
cause this only toggles it on
cause your original question "Menu still visible after pressing ESC"
there is nothing in this code that hides it..
this only makes it appear and pauses the game
ik ik but like its the first step and it doesnt work so thats why im trying it first
why is my code the same color and not autofilling like normal
I used "H" and nthing happens, but first problem is that the Menu is Visible when the scene runs, and its not suposed to
Reconfigure the IDE maybe
because you start the scene with Menu already enabled lol
how
It's just the !ide guides, which I think nav was helping you through earlier?
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
how to change that? Putting ObjetoMenuPausa.SetActive(false) in void start?
just turn the gameobject off in the hierarchy before you hit play
ok
now its done
but when I press H nothing happens
why?
the code is correct isnt it?
make sure its running, but debug.logs
then its not running
where did you put logs , show
if has 0s?
You'd iterate it and check every element
array.Lenght == 0
cant right now, tomorrow, i have a party and i need to buy the vodka and shit
thanks for help but ill go, have a great day everyone

So i originally made an algorithm that will make a solution path and it will fill the whole array with 0s then go through the array and make a snake like path out of 10s 11s and 12s however i converted this to gameobjects for my game in unity and i dont know what to do about the nodes with game objects that have been instantiated

Im having issues with the order of Awake, Start and OnEnable when enabling UI elements any tips?
Wait how do i code "instantiate [GameObject] at every node of the array except for nodes that have previously been instantiated at
loop
also you need a way to check / define that part in the node
dictionary ?
Dictionary?
Does anyone understand why the projectile is not destroyed after colliding with the player? After I play it, the projectile collider and the player collider touch
with Vector3s?
probably because you're not using the 2D version of the method
Thx
it literally doesnt work
i tried practically everything
show us the guide you followed.
vscode thing
link me to it. i want to be certain what you looked at.
show me a screenshot of your package manager with the Visual Studio Editor package selected, as well as a screenshot of the External Tools menu
okay i guess
Yo how do I destroy an already instantiated gameobject?
Hi.
You can use Destroy( pass the object reference here ); on the object you wish to destroy
Remove the Visual Studio Code Editor package.
It is deprecated and no longer needed.
how...
You'll need to remove the Engineering feature, then re-install the Visual Studio Editor package.
how
Features are found at the top of the Unity Registry section
my UI is different, but it's in the same place
The problem is is that the gameobject is in a separate script and was chosen with Random.Range() so if traced back, it will delete a different object
Features mostly exist to install packages you don't want or need, as far as I can tell
Fen are you actually making a game or just have blank project opened just to help people lol
I am working on a game right now, yes
annoying UI auto-navigation problems
You can use GameObject.Find
Oh cool
if you're using it to destroy
How does that work
No this is start strictly
im not seeing it
then store the GameObject reference
i don't understand what the problem is
GameObject.Find(pass the name of the object you wish to find)
clear the search box, if you still have something in it.
oh lol
you already have a reference so I don't understand why you can't just destroy it
and then type its name like this Parent/Child
He wants to destroy from another script
I wouldnt know as the object that was placed is random, and this is a check so i cant just go into unity to see what was placed
store a reference to the object you instantiated.
Can you provide the script
if another script needs to destroy the object, then pass that reference from one to the other.
Could not understand randomness you're talking about
done
now go back to External Tools and make sure it's still set to Visual Studio Code
close VSCode, hit Regenerate Project Files, and double-click a script asset to open VSCode again
That "feature" strikes again...
"Project system initialization finished. 0 project(s) are loaded, and 1 failed to load."
i instantiate the prefab this way, then destroy the instance specifically yet still get this error
my.. code isnt detecting any errors-
!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
follow the VS Code instructions.
okay, now open up the Output tab
ctrl-shift-P, type "output"
should get "Output: Focus on output view" in the palette
hit enter
switch the Output view to C# and look at the output logs.
No
Be mindful, if someone requests your code as text, don't send a screenshot!
Nope
not code related
You can also use shortcut Destroy(gameObject);
i tried sending them all at once but for some reason it only sent one screenshot
But first
ohh there was a VS editor update...
you need to check if it's null or not
Using dotnet configured on PATH
Dotnet path: /usr/local/share/dotnet/dotnet
Activating C# + C# Dev Kit + C# IntelliCode...
waiting for named pipe information from server...
[stdout] {"pipeName":"/var/folders/x2/xqdmgy2d5yx7ylr6xrf7_r440000gp/T/8e8413c6.sock"}
received named pipe information from server
attempting to connect client to server...
client has connected to server
[Info - 11:30:14 PM] [Program] Language server initialized
the whole point is...Dont use screenshots for code..
thats what i thoguht but neither work
"It will be the last object spawned"
So if you spawned C, then D, then E, you want to destroy E here?
well... im not sure how the rest of the code could help, but u prob right 1 sec
put
if (gameObject != null)
if there's nothing else than that looks ok
thats it
so whats the problem then
But i dont know the order they spawn, i spawned C then B then D but i wouldnt know the order they spawn in
explosion script is all in this ss
but here is bomb script: https://paste.mod.gg/kfpjftizkmhf/3
A tool for sharing your source code with the world!
Again , we said the problem last time. YOu're trying to destroy the prefab instead of the instance
yes and i follwoed but u told me to
Create a List<GameObject>.
but it still didnt work
When you spawn something, add the instance to the list.
this website is trash
use the ones in !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.
when you want to destroy something, get the last item from the list if it is not empty
im instantiating it and then putting it in a variable then destroying the variable
Or if you want you can use square brackets
also look at "C# Dev Kit" and ".NET Runtime"
How would that work?
https://gdl.space/zereqotihu.cs bomb (diff website)
well, you would create a List<GameObject>...
Can you send a script
private List<GameObject> spawnedObjects = new();
when you spawn something, you'd add it to the list
dev kit: Starting Spawn .NET server...
Starting Open a solution...
Starting Open a solution with environment service...
Starting Clear environment...
secretStorage: Failed to get secret 'lastPromptDate' from the store. Error: 'Error: Unable to parse decrypted password'
.NET server started and IPC established in 2664ms
Completed Spawn .NET server (3917ms)
Completed Clear environment (4753ms)
Completed Open a solution with environment service (4816ms)
Starting Restore solution...
Completed Open a solution (4836ms)
Completed Restore solution (2688ms)
#getSession: Failed to running method. Error: 'Error: User did not consent to login.'
show the full stack of the error
.net runtime has nothing
And yes fen is correct
ok so send explosion script not this one u sent
its just this: https://gdl.space/wegarukire.cs
and the method is called when the explosions animatyion ends as an animation event
How would that work?
what is internal GameObject thisExplosion;
how is it assigned
Hey just a question, where do you call this DestroySelf Function
Do you have an extension installed named "Github"? I only see one hit when I search for that message.
They just told you
via bomb script when the bomb instantiates an explosion
I was just joking lol
animation event, at the end of the animation for explosion
i dont
I know that the Dev Kit can prompt you to sign in to access paid features...I think it was Dev Kit, at least
Dont instantiate stuff OnDestroy
can you just share all of the relevant scripts so that we aren't playing 20 questions with you
the instance is prob destroyed by the time you use it
okay but how does that help
hmmm so maybe i nthe onCollision method?
i'm trying to think through what's causing the error here
basically before you call Destroy
i see, id have to then copy and paste the same code a couple times
or id just make a method for it i suppose
aight thanks
okay, I recreated that error message by trying to sign in and then backing out
Do you see anything else in the Projects output?
here's mine
sometimes when i open vscode it says i need to sign in again
Project system initialization finished. 0 project(s) are loaded, and 1 failed to load.
But other than that, is there a way to destroy the last gameObject instantiated?
sure, just store the last one you spawned in a variable
done
a list lets you remember many objects
which is relevant if you want to be able to destroy several objects
hm, one thing to try
Wait
go to your project root and delete all of the .csproj files
the instance?
then do Regenerate Project Files again
the thing returned from Instantiate.
project root?
the project folder that contains Assets/Library/etc.
if you went any higher you'd leave your unity project
Alright
in general, the "root" is the top-most thing that everything else is a child of
this?
so i just delete assembly-csharp
I had a weird problem once where Unity was just..appending data to a bad .csproj file
i was getting duplicate assemblies
Never understood why unity creates csproj files everytime you copy a project
ok i deleted it
the .csproj files contain a description of every file in the project
your code editor needs this information
Is ok if you can show me how that would work in code, please. But if you cant, how would you get the instantiated game object because if the gameobject is instantiated and there are other clones of that game object wouldnt destroy destroy all the others?
GameObject foo = Instantiate(prefab);
GameObject bar = Instantiate(prefab);
Destroy(foo);
// bar still exists
Destroy destroys the thing you give it
not other random objects that are sort of like it
Wait
i restarted vscode, and now it says...
ah, that's more what I was expecting
I see, thank you for helping me
You want a cookie?
look at the .NET Runtime output again
er, wrong reply
it's fine
probably suboptimal
since you probably want something more specific than a game object
I dont know whats good or not, i started coding 4 days ago
I thought it would return a gameobject type
well yeah, that's what it does
I don't follow.
PickATwo() returns a GameObject. I presume that some other code then passes that to Instantiate to create a new game object.
It wouldnt even reach the else if random == 5 or the else statement
Oh wait youre right
yes, the range is wrong
it ought to be Random.Range(0, 6) to produce a number in the set 0, 1, 2, 3, 4, 5
yeah maximum value is exclusive
which means it wont be included
I don't really know why unity does that but ig
This 100% should just be an array/list tho where you can just use the collections length as the max index
indeed
[SerializeField] List<GameObject> choices;
it will make your codem uch simpler
you often use integers to randomly pick something from a list
since sequences are zero-indexed, a 10-element list should be drawn with numbers in the range [0, 9]
It's not unity who does it, it's what is done. If you want to use a random element in a list, the list length is 1 higher than the index of the last element.
What's weird is that Unity makes Random.value inclusive
it's [0, 1], not [0, 1)
fun edge case for my weighted random function to trip on someday
I get it now, thanks
Do you want to see my awful code? Its not finished and a lot of lines are left out
so it works like list
because if you set list count to 5, the elements only go up to 4
so do you have any idea what is wrong
did you look here?
It sounds like the .NET Install Tool extension is failing
nothing in there
yes
Failed to find dotnet info from path, falling back to acquire runtime via ms-dotnettools.vscode-dotnet-runtime
Error running dotnet --info: Error: Command failed: dotnet --info
is in C#
/bin/sh: dotnet: command not found
gimme the entire C# output log in a pastebin
why pastebin
because it's probably kind of long and I don't want to clutter the chat more
!code any of these sites is fine
📃 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 about a ss
you could've just sent it in like 15 seconds
i'm not sure why we're talking about this at all
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
okay, all of that seems okay, although the errors from sh are a bit weird (I don't see those on my end)
also on a mac
I'd give the machine a restart for kicks
Yo my final question, when you put the instantiated code in a variable, does it instantiate the code onto the scene when it does that?
no code is being "instantiated"
I meant gameobject
you're passing a GameObject to Instantiate. Unity copies the object (and all of its components) and returns a reference to the new instance of the game object.
And yes, the new object is placed into the active scene.
Not sure why I am getting this message
MissingReferenceException: The object of type 'SphereCollider' has been destroyed but you are still trying to access it.
Your script should either check if it is null or you should not destroy the object.
_TowerDefense.Towers.Tower.SetSphereColliderActive (System.Boolean shouldEnable) (at Assets/_TowerDefense/Scripts/Towers/Tower.cs:25)
The towers are never destroyed in the game atm, neither are the sphere colliders that are attached
Ok fine thanks
is there a sphere collider actually assigned in the _sphereCollider field?
ah, I think I can guess what it is
does OnGameStateChanged fire as the game is quitting?
Yupp
During shutdown, everything gets destroyed
and I believe this happens immediately, rather than..later, at the end of the frame
But this is when I click play
Do you have Domain Reload disabled?
Yupp
GameManager.GameStateChanged is static
ah....
Its contents are not reset between play sessions, because you've disabled Domain Reload
Gotcha
always cleanup your events anyway static or not
You can safely unsubscribe from an event even if you've never subscribed to it
yeah, this would still cause errors even with Domain Reload
as soon as a tower got destroyed
do it in OnDestroy and you should be good
You should 100% be resetting in [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)] if you're not already
OnDisable also runs during destruction, so it would be acceptable
yeah, this attribute is extremely useful for cleaning up during game start (and for getting things ready, even outside the editor)
No idea what this does. Will look into it
I use it to wake up my singleton GameController, which then fires up other parts of the game
If you are not aware of it you should not have domain reloading disabled https://docs.unity3d.com/Manual/DomainReloading.html
I knew domain reload would catch up to me sometime
I like my game to load fast
But yes I understand it comes with implications
Everyone I recommend it to I recommend to thoroughly read those docs
Will do
make sure you have saved
but as seen here
and 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
my code is very different
on vs studio it is saved
and when i open the program thrue unity it shows the same
but on the inspector its different
then you have either turned off the automatic asset refresh and need to manually refresh it. or you are looking at the wrong file
and now my player dosent move
how to refresh?
ctrl+R in the unity editor. also check Edit > Preferences > General to see if you have disabled that setting
im preety sure im looking at the same code
this also does not prove that you are looking at the same file. just that they have the same name
did you change the capitalization of the filename by any chance
like from player_movement.cs to Player_movement.cs
same assets folder aswell and on unity its the same aswell
same capitalisation aswell lol
that doesn't answer my question
did you change the capitalization after creating the file?
okay, so that's not relevant, then
and have you bothered trying to refresh yet? or are you assuming that arguing about the other possibility i suggested will fix it?
I've seen unity get very confused by a case change on case-insensitive filesystems.
and you pressed that in unity, right?
correct
I don't understand the issue with this code
do you have any errors in the console?
in vs or in unity?
!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
please configure your ide
you cannot use a non-static field in the assignment for another field
also yes, get your IDE configured
Is there a good way to rename scripts in unity? I was just wondering if there is a feature or something that allows you to change the name of the script and all references to it at the same time.
could anyone tell me why this isnt working? the enemy has the tag, on the same layer, the ray is hitting the enemy as the something was hit debug is firing off but it won't detect it's hitting the enemy.
and yes the script is connected to my sprite
Log its tag, and log with the context parameter
Debug.Log what you hit ("Something Was Hit") isn't exactly helpful
Debug.Log($"We hit {hitInfo.collider.name} with tag {hitInfo.collider.tag}")
Or use the debugger
in unity it says that there is none... on vs on the other hand it says this
if there are no compile errors and you have saved the code and ensured that the assets have been refreshed and you still don't see the right code in the inspector when you select the script in the project folder then you are looking at the wrong file
Or, errors have been hidden in the console
same name in the same folder
ah yeah, i gotta stop assuming that people aren't just hiding their errors
screenshot your entire console window. also make sure you're actually looking at the right project in vs code
this is my first time using unity so im kinda new to this
im running the project rn theres litterally NOTHING here
thats what weirds me out
How often should one use Debug.Log?
as often as you need to print something to the console
As much as possible until you learn debugger
then use both
Cool
full screen of both the file tab and console tab
yeah so at this point i'm going to assume you're looking at the wrong file and probably just have two files with the same name in your project
because it's either that or you have not actually saved and refreshed the assets
did the ctrl R thing which u sayd so thats not it....when i open the code its the code i did actually write in vs
so thats aswell off the list
screenshot your entire vs code window
entire window
that file is not saved
well, it's currently unsaved
literally the first thing i said to do
sorry im new to unity lel
I googled it and still don't understand, I also compared it with a very similar code that works, how do I fix it?
and why is the highlighting so bad, is it just partially unconfigured?
now how do i save it lol?
i dont mainly use vs studio but im using it currently bc its easyer for unity [as im told]
assign to that field inside of a method like Awake or Start rather than where you are declaring it
visual studio is better and easier for unity than vs code (which is what you are using)
ty, solved the issue, was hitting another thing
Visual Studio Studio ?
have you never saved a file in your entire life? also you know google is a thing too
my bad lol
i did it
lol
EXCELLENT new errors -_-
get your !IDE configured then fix your spelling mistakes
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
ok ty alot for the help and sorry for making yalls lives kinda hard lol
It literally tells you to edit your messages instead of posting like this
Ok, I really tried but I just dont understand which field
before i provide any more details, is your IDE configured yet?
I think so
if you are unsure then screenshot your entire IDE window and send it here
that is unity
why do you have VS selected but showing VScode
Could I get any help with Cinemachine Cameras? or does anyone have alternatives for a 3rd person camera!?
also if you have visual studio installed, you should really consider just using that instead of vs code
tyty
Bro I'm literally sleepimg
did you click Regen Project Files after selecting VSCode ?
chances are you scripts are still tied to VS
I did
it should just use the same project files since the same package is generating them
did you install the c# extension? and if you only just installed it, have you restarted your computer since doing so?
i have a question about my code
this is where u ask?
what does the channel description say?
ahh ok thats true
Cause last time VSCode complained for me that's why I do it
I think I had installed it with VScode
Not sure tho
You need the Unity extensions
My files are C#
I have it too
wdym you are not sure? installing it is part of the configuration guide and surely you followed that, right?
I have
im testing out a 2d bullet code game and when shooting my bullets always shoot right
is there a fix for making the bullet shoot in the direction of the player?
open script through unity again and show the VScode Output window
You can post !code inline or using an external service(free as well). Other than that, you're trying to use a position as a direction for velocity.
📃 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.
isn't .up a direction ?
Large code blocks should not be placed inline
I'm too tired for this, I'll just fix it tomorrow
Thx tho
takes 1 second to just open it, You had VS selected but now VSCode
maybe its already working..
its working
Ah you're right. It's a transform component and not simply a point
lol
Thanks
yeah! just strange its using world point somehow
unless OP had Global on
I'm gonna go to sleep
The name implied it was a point
Would bar still exist and would the prefab/gameobject be instantiated into the scene in unity?
GameObject foo = Instantiate(prefab);
GameObject bar = foo;
Destroy(foo);
Both foo and bar refer to the same C# object
They're two variables that both happen to refer to the same thing
References you're just passing around the same object,
its not cloning or anything
you can use mathf.clamp() instead of if (shield>shieldCap)
not much more effective but ye
Hi everyone, I definitely made a bit of confusion in the calculations, I use the character controller, and my aim was to add gravity to the character and so far so good, my problem is when I click play on my character instead of standing with my feet on the ground, it goes up (but immediately stops) on the y axis
(I hope I've made myself clear, if so I'll make a clip)
this is code:
https://pastebin.com/FWvbz0M6
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
Instantiate creates one instance. You're referring to the instance using foo and bar.
you're adding gravity to your movement vector after you reassign movement
that's not accomplishing anything
I'm guessing your character goes up because the character controller's "Center" property is wrong
make sure the capsule is resting on the ground, not stuck in the floor
e.g.
this is fine
god those ragdoll colliders are so broken
the character's position is fine, it's not stuck in the floor
but as you said, I definitely got confused in assigning, when I walk the character from position y = 0
rises in position y = 0.07999706
oh, that's just the skin width
the character controller has a little bit of extra margin around it
I'd suggest just offsetting the controller so that it's 0.08 meters above the ground
You can also reduce the skin width of the controller. I haven't really seen any catastrophic problems from doing that yet
but it nominally could make collision worse
anyone have an idea what this error could be? PlayerEquipment is not being destroyed
Your script should either check if it is null or you should not destroy the object.
UnityEngine.Component.TryGetComponent[T] (T& component) (at <30adf90198bc4c4b83910c6fb1877998>:0)
PlayerEquipment.UpdateWeapon (Weapon weapon) (at Assets/_Scripts/Player/PlayerEquipment.cs:22)```
well, it is
unity doesn't show you random error messages for fun
perhaps one PlayerEquipment still exists, but another has been destroyed
its still on my player when the error is showing though
could it be because of
{
equippedItems = new Equipment[10];
foreach (ItemStack equip in gearInventory.GetItemList())
{
EquipItem((Equipment)equip.item);
}
}```
that doesn't matter if something else is trying to access a destroyed instance
where i reset the array
share the entire script: !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.
okay, so UpdateWeapon is being called on a destroyed instance of PlayerEquipment
You get this exception when you attempt to call TryGetComponent on the PlayerEquipment
and where do you set instance?
perhaps in the Start method of UnityHandler?
then it's probably happening after you try to use instance in another component's Start method
Assign it in Awake instead. That runs before any Start method will.
okay 👍
what do you think is causing playerequipment to be "destroyed" even though its still on my player
Log the object before you try to call UpdateWeapon on it
do it like this:
Debug.Log("The equipment: " + myPlayerEquipment, myPlayerEquipment);
If myPlayerEquipment is valid, clicking the log entry will take you to it
You could also log this to find out who is trying to call UpdateWeapon on the PlayerEquipment
I'm guessing you have a stray component somewhere
What's the full stack trace? Surely it doesn't start at UpdateWeapon
Your script should either check if it is null or you should not destroy the object.
UnityEngine.Component.TryGetComponent[T] (T& component) (at <30adf90198bc4c4b83910c6fb1877998>:0)
PlayerEquipment.UpdateWeapon (Weapon weapon) (at Assets/_Scripts/Player/PlayerEquipment.cs:22)
PlayerEquipment.EquipItem (Equipment equipment) (at Assets/_Scripts/Player/PlayerEquipment.cs:71)
PlayerEquipment.UpdateEquipped () (at Assets/_Scripts/Player/PlayerEquipment.cs:51)
PlayerStats.UpdateStats () (at Assets/_Scripts/Player/PlayerStats.cs:93)
PlayerStats.LevelUp () (at Assets/_Scripts/Player/PlayerStats.cs:52)
PlayerLevel.LevelUp () (at Assets/_Scripts/Scriptable Objects/SO Scripts/Entities/PlayerLevel.cs:31)
PlayerLevel.AddExperience (System.Int32 amount) (at Assets/_Scripts/Scriptable Objects/SO Scripts/Entities/PlayerLevel.cs:25)
PlayerStats.AddExperience (System.Int32 amount) (at Assets/_Scripts/Player/PlayerStats.cs:46)
UnityEngine.Events.InvokableCall`1[T1].Invoke (T1 args0) (at <30adf90198bc4c4b83910c6fb1877998>:0)
UnityEngine.Events.UnityEvent`1[T0].Invoke (T0 arg0) (at <30adf90198bc4c4b83910c6fb1877998>:0)
ListenerBase`3[T,E,UER].OnEventRaised (T item) (at Assets/_Scripts/Game Events/Event Listeners/ListenerBase.cs:26)
EventBase`1[T].Raise (T item) (at Assets/_Scripts/Game Events/Events/EventBase.cs:13)
Enemy.Die () (at Assets/_Scripts/Enemies/Enemy.cs:87)
Enemy.TakeDamage (System.Int32 damage) (at Assets/_Scripts/Enemies/Enemy.cs:40)
ExplosionProjectile.OnTriggerEnter2D (UnityEngine.Collider2D collision) (at Assets/_Scripts/Equipment Logic/ExplosionProjectile.cs:23)```
it happens when I level up
Show the event you're subscribed to
its just an int event for xp
okay, and how is it declared
the issue isnt the event
Okay then, good luck with the issue that you apparently understand
the error starts happening when I level up which causes PlayerStats to reload all of the gear and update the weapon
the event just adds xp
and it works
Unity wont allow me to add scripts and i cannot put gameobjects with the scripts what is an alternative?
Are you looking at a prefab?
Yh
Do you have domain reload disabled?
You're likely not resetting or unsubscribing from your event
If it's occurring in a build then is it happening after a scene change?
I am unsure how your event script works, but if it's got statics then it needs to be cleaned up in [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
As it's an asset, if it's not unsubscribed from it'll persist between scenes, which will cause the issue
if an object already has velocity, will making the gravity scale be 0 stop it in it's place
the issue wasnt with my xp event it was a c# event i forgot i had
How does the SphereCastNonAlloc work? Like it doesn't return the closest object to be found, how can I make it work as such?
what's this error?
it returns anything in the sphere
with a colliders
I was expecting the results to be sorted by distance, but its not the case, and the documentation also says that
does anyone have an idea on why it wont let me drag the game objects to the slots?
not always true, so you should foreach through it and sort it
you're trying to access something in array but the index you passed is not found its either more than list size or negative
which gameobjects, these cropped out photos are not helpful at all
the script is not on a gameobject 😉
ah okay that makes sense thanks
is this a code error or unity error
it even spelt commander wrong
unitType.Commander, not Commander by itself
u sure? it only appeared for commander not the other units
Wait, your trying to set Unit to an enum?
ye
where is the string coming from because it certainly isn't related to that enum
Yes, but there is a lot more wrong here than that
How is the compiler supposed to set Unit type to be an unitType enum?
