#archived-code-general
1 messages · Page 284 of 1
Okay. Got right now I just have an empty holding my vehicle interact handler. The interact handler is what controls camera positions exit position and enabling and disabling certain scripts to make the transition from moving the player to moving the vehicle
Also is there any way to separate parts of vehicle out inside of unity. The prefab model that I have has one part of the vehicle that I would like to animate but it's not separated out like the rest of the intended movable parts are
Turning off "Show new snippet experience" solved this issue, so far.
hey there, I'm trying to use the unity nav mesh for my 2d game. Is there any good resource how to use it in a 2d environment? I know there is a NavMeshPlus for 2D but is there any other way to use the official pack for 2d?
Nope, navmesh plus is it really
private void Update()
{
Vector2 thrustInput = playerControls.Player.ThrustControl.ReadValue<Vector2>();
float yAxis = thrustInput.y;
float xAxis = thrustInput.x;
//float SpaceBreakValue = playerControls.Player.SpaceBreak.ReadValue<float>();
//rb.velocity *= (1f - SpaceBreakValue);
ThrustForward(yAxis);
Rotate(transform, xAxis * -rotationSpeed);
//Store ship data for UI
currentVelocity = rb.velocity.magnitude;
currentHeading = -rb.rotation < 0 ? 360 + -rb.rotation : -rb.rotation;
}
I needed some advice on this. Normally when you'd use Input System, people would make a separate function that would run when the button is pressed. All though press events. However in my code currently, the Thrust control of the spaceship is based on a value outputted instead of a button. Is this fine to have? And should I do the same for the space break when added? I want to have clean code.
what do you mean "a value outputted instead of a button?" what is the "value outputted"?
do you mean in the inputsystem, when you press a keyboard key (or some other input button pressed such as mouse or joystick), you call a function, but in your case, that function is called through a different mecahnism you call "the value outputted?"
I just came across a weird interaction, if I write Object.Instantiate(prefab, position, rotation), and my prefab has an Awake method, then the position and rotation will not yet be set during its Awake ?! It sounds super counter-intuitive, is that intentional ?
Value outputted means this. Basically a Vector 2 value for button presses instead of it just being a button action.
Hey guys, I written here before about my Saving system in game and now I finally did all changes some of you said but it doesnt work, I dont get any error but when I click save my data and in my main menu click load game button it should load game with all data saved but it doesnt. Here is SaveServiceScript that is responsible for saving and loading my data: https://hastebin.com/share/uwizavokit.csharp here is GameState script where I save all of those variables: https://hastebin.com/share/agomeyoqab.csharp and here is my menu manager script that has function that when I click on Load Game button it should load scene 1 with all data saved: https://hastebin.com/share/sapiyeduga.csharp
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
You need to use Debug logs to find out where the specific issue is, then
like how far does the code get
does the method get invoked
you don't do anything with the gamestate after you load it
does it actually write a file
that’ll do it lol
like I don't know what other classes you have, but you need something like:
public void LoadFromJson()
{
string json = File.ReadAllText(Application.dataPath + "/GameDataFile.json");
GameState data = JsonUtility.FromJson<GameState>(json);
GameManager.instance.state = data; // <---- use the thing you just loaded
}
how to fix that then, I had saving system working before but I had to reference gameobjects inside saving script which I was told isnt good way and I couldnt make Load Game button work in my main menu with that script so now i rewrote it that inside player/cam script they reference saving script to load it
i dont have gameManager and it doesnt have state in it im confused
On unity ads, if a user doesn't click the cross (X) at the top of the screen to close the rewarded ad, although they wont receive the reward, BUT will I still receive the money for that ad being watched?
Not a coding question #🔎┃find-a-channel
well looking at the save function, you need to do the reverse in load:
public void LoadFromJson()
{
string json = File.ReadAllText(Application.dataPath + "/GameDataFile.json");
GameState data = JsonUtility.FromJson<GameState>(json);
//use the thing you just loaded
FindAnyObjectByType<PlayerController>().deathCount = data.deathAmount;
FindAnyObjectByType<PlayerController>().PlayerCamera.transform.position = data.camPos;
FindAnyObjectByType<PlayerController>().player.transform.position = data.playerPos;
FindAnyObjectByType<CamController>().maxPos = data.camMaxPos;
FindAnyObjectByType<CamController>().minPos = data.camMinPos;
}
Okay I will do that thanks
Yo! Do you guys have tips on how to implement animations in my project ? I started working with animations using the animator with the graphs and it rapidly became a total mess. I'd like to know how what you do in your own projects please.
I think your way of doing things is fine if you truly need the input value every frame. Button -> function is for event based input, where checking if the button is down every frame or something is considered wasteful.
So things like movement such as Spacebreak and thrust control should be values. And something like firing a projectile is a button?
Sounds reasonable.
gotcha
idk if I am doing something stupid or unity has brain damage. Every few minutes, despite my rotation value staying the same, it will go from a slow rotation to a fidget spinner out of nowhere.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
public class AdvancedPlayerMovement : MonoBehaviour
{
private Rigidbody2D rb;
public float maxVelocity = 3;
public float rotationSpeed = 2f;
public float brakeDeceleration = 0.1f;
#region Monobehaviour API
private void Start()
{ ... }
private void Update()
{
Vector2 thrustInput = playerControls.Player.ThrustControl.ReadValue<Vector2>();
float SpaceBreakValue = playerControls.Player.SpaceBreak.ReadValue<float>();
float yAxis = thrustInput.y;
float xAxis = thrustInput.x;
ThrustForward(yAxis);
Rotate(transform, xAxis * -rotationSpeed);
if (SpaceBreakValue == 1) {
SpaceBreak();
}
ClampVelocity();
}
#endregion
#region Maneuvering API
private void ClampVelocity()
{
Vector2 x = Vector2.ClampMagnitude(rb.velocity, maxVelocity);
rb.velocity = x;
}
private void ThrustForward(float amount)
{
Vector2 force = transform.up * amount;
rb.AddForce(force);
}
private void Rotate(Transform t, float amount)
{
t.Rotate(0, 0, amount);
}
private void SpaceBreak() {...}
#endregion
}
Last night it was set to 0.5 which would spin at like 1rev per second, then this morning it was EXTREMELY slow, going like 1rev every 4 seconds. So I changed it to 3 and it was 2revs per second, and then this last time I ran it it was a good 100 per second.
You're doing exactly what you're not supposed to do, which is physics in Update.
Physics code belongs in FixedUpdate
oh, should I move everything in update to FixedUpdate?
Also with your rotation code you're not adjusting it for the framerate
You're also mixing Rigidbody motion with Transform rotation
All of these things need to be addressed
I am honestly not sure how to adjust for framerate? I remember Time.deltaTime methods being used in the past but I don't fully understand how to do that
Time.deltaTime is used yes
It's not a method
Just a number you multiply into your "per frame" quantities to turn them into "per second" quantities
But that would only be for when you are manually doing things in Update
If you're doing physics in FixedUpdate you don't need it
So aslong as the rotation and other items are in fixed Update its good to go?
Just for reference I followed this guide to help me with my zero G movement: https://www.youtube.com/watch?v=XXfgdEE4S20
I belive hje used the transform rotation so exzerted forces are always where you face
90% OFF Make Your First Game Course ► https://www.udemy.com/make-your-first-game/?couponCode=MAKES-GAMES-NOW
Free Make Your First Game E-Book! ► http://xenfinity.net/game-dev-tools-book-landing-page/
Get Personal Answers to your Questions on Reach.me ► https://www.reach.me/xenfinity
Hey developers,
Bilal here, and In this video, I'm excited...
Rather than trying to find rules of thumb, you should try to think about what your code is actually doing exactly and what it means when things go in different places. Putting your rotation in FixedUpdate will make it consistent but also it will look jittery because Transform.Rotate isn't going to be interpolated
The Rigidbody interpolation, which you should be using, only applies to motion from the Rigidbody
Would the ridgebody method for that be SetRotation?
You'd apply an angular velocity, use AddTorque, or MoveRotation
Check the docs for Rigidbody
gotcha
hey, I added this and first time I tried to save and then leave and load game it worked and I was spawned there with my camera pos and player pos same as it was after I saved but then I tried to go to different room and save and load game and it spawned me back where I was at the first save with same data. So it worked first time but every other time it just spawned me where I was firstly saved
I added this to code as u said btw
if you open GameDataFile.json you might be able to sus out what's happened. I can't tell you off the top of my head why it won't overwrite your old save, and I'm about to head out rn. if not hopefully someone else here has time to look in to it. gl
hi actually i am getting null reference error but can't understand why it is happening
check the script of the error line posted in the error. we can't tell anything without the code in question . . .
you have cropped out all of the line numbers
did you check if gameUI is null?
that's the only variable on the error line . . .
ahhhhh it worked earlier i created a variable for script gameui but that was null now i used singleton and it worked
Hi guys, I have a problem with my Saving system in Unity. When I click on Save button it should make .json file with all game data saved and when I load the game from main menu it should just load me that data but for some reason it doesnt. Here is saving script: https://hastebin.com/share/efobihiduv.csharp and here is GameState script where I save all variables: https://hastebin.com/share/riniyipemi.csharp . Also in Saving script my Debug that says "save" doesnt appear but it worked before and I havent changed anything...Im very confused because my saving script worked 5min ago and I saved my game, then I loaded game from main menu and worked perfect, I tried again with different values(different player and cam pos and death count) I saved and loaded and then it loaded save values that I saved before. It didnt overwrite .json file and I dont know why. Then I deleted that .json file and now it wont even save nor load data...
What debugging steps have you taken?
don't crosspost; you just asked about this in #💻┃code-beginner a few minutes ago
it was 20min ago and this is fuller desc
I only put debug after save and load func was called, I tried saving multiple times after I deleted .json file but it didnt work, it wont make another .json file with saved variables
Yo, I need help, I want the main camera to rotate relative to the mouse at x and z coordinates around some object when I move the mouse. But my code I wrote looks terrible, and I don't know how to implement it.
Well is it printing?
save debug doesnt show and load wont show because of this error
which occured after I deleted my .json file
Seems like REALLY important infomration you should have provided lol
click on it, read the full error message
Find the filename and line number where it's happening
I am trying to figure out how i reference the object my script is attached to in a public variable ?
ah sorry
goes here
the object your script is attached to is always .gameObject, you don't need a separate variable for it
ok well that's your problem
you'
re trying to read a file that doesnt exist
so it's throwing an exception
Well your code expects it to bne there
and then rewrite it after I save again
so you need to make your code able to handle the possibility of the file not being there
trust me I do, it is kinda difficult to explain the scenario but i do need it
you don't
I guarantee it
explain the scenario.
what should I do then
i.e. check if the file exists before you try to read it
I am making an enemy spawner and because i made the object a prefab i cannot refer to one of the objects in the script becuase it is not in the assets folder, it is in the hierarchy so I am going into a script connected to the object that i need to refer to, and I am making a global variable so i can access it in the other file
I have a question related to Zenject. I have a MonoBehaviour script and a service. Where should I implement the movement logic, and what should I do with the basic components (e.g., Rigidbody2D, etc.)? I'm not quite sure how to properly design this. Can you help me, please?
it is a weird work around i know
okay but when I save it should make one, this lines of code
The correct way to do this is keep all your references that are internal to the prefab on a script at the root of the prefab. Other wcripts outside the prefab should not generally "reach inside" the prefab, as a best practice
that's not relevant to the other problem though
Debug.Log("saved"); doesnt show up when i click save button
you're trying to read it before you write
no, after
then that has nothing to do with this code that means this code isn't even running
then how am i supposed to refer to the object i need to refer to
I first save and then I click load
you messed something up and you're not even calling this now
As I said, from a script on the root of the prefab
which can refer to objects inside the prefab no problem
oh you are right
my save button had save service attached to it but it doesnt now cause I made it ddol and it doesnt exist in scene
it might help if you share some code then I can explain better.
how can i make my button find reference to SaveJson func
i think you misunderstand, I need to refer to an object out side of a prefab but in a hierarchy
in the button inspector
you need to drag the object that has the script into that slot, then assign the function
Show screenshots and code
I will help you with the best way
of what
of the object you want to refer to, and the object that you want to refer to it
and the spawner thing
like - explain your situation better.
k 1 sec
yes I know that but that gameobject with SaveServiceSystem script is DDOL and I cannot drag and drop it cause it exist only in main menu before I load game
you get what im saying?
Isn't it a singleton?
Attach a different script to the button with this code:
public void Save() {
SaveServiceSystem.instance.Save();
}```
and assign that in the button inspector
hey guys, I've just downloaded the Starter Asset-FirstPerson. When playing the game in the Editor and trying to look around with the mouse, I cannot look around as much as I want. The view is locked to mouse cursor position on the screen. So when the cursor hits the edge of my desktop screen, looking in-game stops. Is it possible to make it that I can infinitely scroll and look around, please?
oh yea that will work, thank you so much!
The first 2 images are of the object that needs referring to and the 3rd image is the script which refers to the object that needs referring to (lookObject = the object i need to refer to in the first 2 images) and the code is the inspector for the object referring to the object that needs referring to. https://hastebin.com/share/efenupobay.csharp
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
For example, I cannot look to the right, if my mouse cursor is already to the far right of the screen:
I don't know much about the starter assets, but usually you'd lock the cursor in code. Maybe for some reason that doesn't run/work in the asset. Should look through it's code and debug.
thanks. the same thing happens even when cursor is locked/invisible. it's as if when the cursor hits the edge of the screen, it's then that it prevents me looking in that direction
hm, I just built the game and executed the exe, and even in full screen it behaves the same. It might be because I'm developing on a virtual machine. When I copied the binaries locally, the exe works as expected
i have a Vector 3 array
Vector3[] vertices = new [] {};
and i want to add to that
vertices.Add(new Vector3(1, 2, 3));
but that doesnt work
what do i do instead?
i made a generic class that requires the ability to check if instances of the generic argument are null or equal to each other. I currently have T : class. Is there a way to expand this sort of thing to have an enum type in the argument?
maybe with like a MyEnum? ?
doesnt work because MeshFilter.mesh isnt a list
instead its an array
cuz im doing this
MeshFilter.vertices = vertices
then run, vertices.ToArray(); when you assign it.
mk
i am planning to learn C# but i want to only learn the essentials. does anybody know a simple and short tutorial
check pins in #💻┃code-beginner
mk that seems to work fine
go as far as you['d like
there is about a million 'how to c#' tutorials online, written and video. I've heard good things about the brackeys series, if you prefer video and 'interactive' learning.
but I have no personal experience with it
https://www.youtube.com/watch?v=N775KsWQVkw&list=PLPV2KyIb3jR4CtEelGPsmPzlvP7ISPYzR
Coding can seem scary at first - but it's actually not that hard! Let's learn how to program in C#.
Jason no longer offers the course mentioned in the video.
● Download VSCode: https://code.visualstudio.com/
● Download .NET: https://dotnet.microsoft.com/
👕Get the new Brackeys Hoodie: https://lineofcode.io/
···································...
from what i understand these tutorials assume youre a beginner so it explains many things, but i already have some programming experience. is there a quick tutorial that explains the C# syntax and maybe some intermediate topics?
i dont necessarily need one that goes into many details, but gives broad context
maybe C# discord knows more
I can give you the essentials of c# in 4 words
types
methods
keywords
scope
do with them what you may
that isn’t really helpful
wasn't meant to be, the question itself was nonsensical
it isn’t nonsensical
he needs an intro to C#, focusing on syntax, given he already understands basic programming
really? C# without .Net is virtually worthless, there is no 'essential' .Net
And syntax is exactly covered by the 4 words I used
the manual is your best bet
Is there a way to get AssemblyDefinitionAsset's root namespace in C#? It seems they integrated the **AssemblyDefinitionAsset **class as a **TextAsset **which has no variables in it.
Maybe i could convert to Json object and try to get it from there? Or even more creating a static class for it would be helpful
how can I multiply a colour to the base colour of a shader graph material
similar to how you would blend 2 colours in multiply mode in photoshop
https://docs.unity3d.com/Packages/com.unity.shadergraph@6.9/manual/Blend-Node.html
But honestly just the multiply node would work too
Thank you, I did just find a solotion with the SetColor method
i cant tell why but when i have the Random.Range(0, 1), this whole thing just renders no voxels
List<int> chunk = new List<int>();
// place random voxels within chunk
for (int i = 0; i < chunkSize*chunkSize*chunkSize; i++)
{chunk.Add( Random.Range(0, 1) );}```
this always returns 0
how so
is there anyone thats really good at creating 2d platformers or games here if so could u dm me
im looking at that and its confuzzling me
i dont know why Random.Range(0, 1) only returns zero
because you gave it integers
maxExclusive is exclusive, so for example Random.Range(0, 10) will return a value between 0 and 9
what part of that is unclear or confusing
they expected the behavior it has with float arguments
rite
there are several overloads for the Random.Range method
one takes floats and returns something from the inclusive range (so, Random.Range(0f, 1f) could theoretically return 1)
the other takes integers and returns something from [minValue, maxValue)
excluding maxValue
so its just returning 0.48549 or something instead of just 0s and 1s
no, it's returning exactly 0
because it rounds it down?
they're asking how it behaves with floats
as compared to how it behaves with ints
are they?
so, yes, Random.Range(0f, 1f) produces floats between (and including) 0 and 1
i thought maybe its because its doing a range between floats instead of between ints like i want it to
now I can't tell 😛
Your code is calling Random.Range with integral arguments.
This means that it produces numbers in the range [0, 1)
the only number in this range is 0
This has nothing to do with floats being rounded.
If you want to get floats in the range [0, 1], then you need to call Random.Range with floats, not integers
the chunk is list<int> so changing it to float overload doesnt help
so would Random.Range(0, 2) return 0s and 1s?
I missed that! That makes more sense now (:
i feel like you couldve explained that way easier
I thought you were looking for floats, so this confused me
now that makes sense
And, indeed, if you did do this:
chunk.Add(Random.Range(0f, 1f));
You'd get almost exclusively zeroes, since converting from float to int truncates the number.
(unless you got the extremely rare outcome of it returning 1.0f)
0, 2 is still giving me no voxels
either that or exactly 3 of them
its prolly something stupid with the rest of my code but its strange nonetheless
check the numbers you're getting!
its given me 4 this time actually
yeah its giving me 0s and 1s but still doing nothing
if i replace the Random.Range with just a 1 then it renders every voxel
show your new code
{chunk.Add( Random.Range(0, 2) ); Debug.Log(chunk[i]);}```
Maybe your code is stopping early when it hits a zero?
good idea
yep that adds up
i had it like this
{
do stuff;
vx++;
}```
but since vx++ was inside that loop it never went onto the next voxel
yep its a randomised chunk now
and yeah i havent bothered drawing the whole voxel yet, just one triangle
havent gotten round to it
Yo ! I really need some advices on how to implement animations, when I try to setup my animations it become really messy really fast please.
where is the code question ?
I know that it is possible to implement animations in code. What should I use, code based or graph based ?
thats up to you?
For a not so tiny project is it possible to do everything in graph ? Or does it takes way to much time compared to code ?
That's pretty awful, if you want randoms 0s and 1s, I'd recommand Random.value > .5f ? 0f : 1f
Added bonus of controlling how many you get of each
@tawny elm Random.Range(0, 2) will return exactly 0 or 1
Random.Range(0f, 1f) will return a float value between 0 and 1
i already fixed it
the problem was over like 10 minutes ago
if by graph you mean Animator, yes its pretty fast to do and has many benefits like Blend Trees
Yes I mean animator. I'm currently using these, but do you have tips & tricks or maybe just a guide on how to properly use it ? Because it gets really messy really fast, many things are linked together and I feel like i'm not doing the right thing
I dont have a specific tutorial , they have too many already. Generally you just link states with the transitions and you're done. Kinda hard to fuck it up tbh its easy as shite
just make sure to use https://docs.unity3d.com/Manual/AnimationParameters.html
lmaoo
I'm not talking about not being able to do it, i'm talking about being able to do it properly so that it is readable and can be expanded rapidly
Yes I already use that but thanks 👍
public abstract class Something
{
public Something() {/*do stuff*/}
}
public class Foo : Something
{
public Foo() {/*do other stuff*/}
}
Foo foo = new Foo();
Will the abstract class's constructor run alongside Foo's constructor?
For example my movement animations look like this, but if I have to add something I will need to add links everywhere and it gets messy
welcome to Animator hell
also most of those can be a simple blend tree
Idle,walk,running,Spriting
Not in this case because of how the movements works, but I know about blend tree 👍
bruh... I will look at code based then lmao
wdym "because of how the movements works"
oh! that's kinda cool...
I have a question related to Zenject. I have a MonoBehaviour script and a service. Where should I implement the movement logic, and what should I do with the basic components (e.g., Rigidbody2D, etc.)? I'm not quite sure how to properly design this. Can you help me, please?
do you know why you are using Zenject in the first place ?
i don't think anyone knows why they're using Zenject, to be fair
I tried to read the readme and woke up 74 hours later in a field
Hello, is the 1st assignment of the position nullified if set before the 2nd in Update?
private void Update()
{
transform.position = newPos; // 1st
transform.position = newNewPos; // 2nd
}
So is it exactly the same as just setting the 2nd position without the 1st one?
Nullified? No. Overwritten? Yes
This is indeed pointless
Actually, I know why I use it, and I feel much more comfortable when using a composition root
Got it, I've expressed myself wrong
So no visible changes are noticeable for the player, right?
No
No, not noticeable?
well, then identify places where you need to supply one of many possible concrete implementations, and use Zenject to provide those concrete implementations
I currently have an Minimum Spanning Tree, does anyone know of any algs that are used to find the max weight/length with only the coords/weight? ie. get from a to b, but i don't know a or b to begin with
Otherwise will just have to throw iterations at it 
That doesn't look like a spanning tree since there are untouched rooms unless I'm misunderstanding something
yeah, that's not a spanning tree at all
I'm sampling the rooms rather than doing every single one
if you just want the longest path, you'll need to compute all-pairs distances
Also I'm unclear what you're asking. Are you trying to get a path from a to b?
if you want a maximum spanning tree, that's pretty trivial https://mathworld.wolfram.com/MaximumSpanningTree.html
how do i edit stuff that is greyed out like that?
you don't. these assets are from packages, or are a sub-asset of another asset.
Make a new material and edit the new one
Yes that's called using a different material as suggested
yeah, except i wouldn't know where a or b is to begin with 
I don't really understand the question then. You want the longest path in your set of edges?
Like ticket to ride longest train?
yeah
Or Catan longest road
ticket to ride longest train sounds about right
Iterate through each node in your tree and do a DFS from each. Pick the one that reached the greatest depth
Hi everyone, I'm here to find some help because I'm a new user to Unity so I would like to know how to change the texture in the Mac version?
it did sound like dfs was what i'd be after! good to know i was on the right track somewhat, thanks 
Unity works the same way on all platforms
"change the texture" is vague and doesn't sound like a code question unless you mean changing the texture of something in code
I went to the wrong salon where can I ask for help using unity?
You can change materials through either the editor or through code
thx
Hi, I'm having an issue with an error which appears on the console everytime I open the editor. Says the next message:
at UnityEditor.WindowLayout.LoadWindowLayout (System.String path, System.Boolean newProjectLayoutWasCreated, System.Boolean setLastLoadedLayoutName, System.Boolean keepMainWindow) [0x00109] in <2e279d988b9d4542841de511fbfdf8c2>:0
UnityEditor.WindowLayout:LoadDefaultWindowPreferences ()```
After a lot of debugging, the only thing I could make sure of is that it only happens when I use the ``Templates`` property of [this script](https://paste.ofcode.org/8PAN83AUykqFGP8vGWuLbN).
And yes, ``JsonTemplateData`` is serializable. This is the whole class:
```cs
[System.Serializable]
internal class JsonTemplateData
{
public string TemplateName;
public bool MultipleInstances;
}```
Does anyone know what could be happening?
i'm guessing that just happened to trigger the error
Are you on the latest patch version of the editor?
(so, the latest LTS version, if you're using the 2022 LTS)
I'm on 2022.3.9f1, so yeah
that is quite old
I'll try using a newer version
the latest is 2022.3.21f1
Thank you, I'll try installing it
Just tried it, stills gives the error
I Broke Hold Notes. Again.
can you serialize a MyEnum? as a nullable type?
Total shot in the dark, but have you tried deleting, and letting it rebuild the Library folder?
You can serialize things as a nullable type?
i am asking
As nullable no- an enum is effectively and int, behind the scenes.
i mean i guess Nullable<Enum> could work? Haven't tried it but i think it just allows to do that in code rather than in inspector
i am making a hierarchy of enums, and need a way to indicate “this thing has no parent”
you'll need to make that one of the enums
why not just a value of NULL for enum itelf
anyway you can do it iirc anyway
since they are value types
how do you set a null value for a value type tho
Make a None value in your enum
yup x2 on that
Nullable type is of course an option too, it's equivalent to using a separate bool variable
it's a value type, like an int.https://learn.microsoft.com/en-us/dotnet/csharp/misc/cs0037?f1url=%3FappId%3Droslyn%26k%3Dk(CS0037)
damn. I did a big dumb when I defined this thing a long time ago LOL
yes I know that, thats why it can be nullable
any value type can be made nullable with ?
ya, that works- dammit nav, now I need to learn how those guys get serialized!
spoiler alert : in unity they dont
what about stuff like BinarySerializer?
for some reason the UVs dont work on the top and bottom of the cubes im procedurally generating here?
uv.Add(new Vector2(0.0f, 0.0f));
uv.Add(new Vector2(0.0f, 1.0f));
uv.Add(new Vector2(1.0f, 0.0f));
uv.Add(new Vector2(1.0f, 1.0f));
uv.Add(new Vector2(1.0f, 0.0f));
uv.Add(new Vector2(1.0f, 1.0f));
uv.Add(new Vector2(0.0f, 0.0f));
uv.Add(new Vector2(0.0f, 1.0f));
This code snippet doesn't have enough information to know what's wrong.
vertices.Add(new Vector3(i , j , k )); // 0
vertices.Add(new Vector3(i , j+1, k )); // 1
vertices.Add(new Vector3(i+1, j , k )); // 2
vertices.Add(new Vector3(i+1, j+1, k )); // 3
vertices.Add(new Vector3(i , j , k+1)); // 4
vertices.Add(new Vector3(i , j+1, k+1)); // 5
vertices.Add(new Vector3(i+1, j , k+1)); // 6
vertices.Add(new Vector3(i+1, j+1, k+1)); // 7
// triangles
// front
triangles.Add(vt+0); triangles.Add(vt+1); triangles.Add(vt+2);
triangles.Add(vt+2); triangles.Add(vt+1); triangles.Add(vt+3);
// left
triangles.Add(vt+4); triangles.Add(vt+5); triangles.Add(vt+0);
triangles.Add(vt+0); triangles.Add(vt+5); triangles.Add(vt+1);
// right
triangles.Add(vt+2); triangles.Add(vt+3); triangles.Add(vt+6);
triangles.Add(vt+6); triangles.Add(vt+3); triangles.Add(vt+7);
// back
triangles.Add(vt+6); triangles.Add(vt+7); triangles.Add(vt+4);
triangles.Add(vt+4); triangles.Add(vt+7); triangles.Add(vt+5);
// top
triangles.Add(vt+5); triangles.Add(vt+7); triangles.Add(vt+1);
triangles.Add(vt+1); triangles.Add(vt+7); triangles.Add(vt+3);
// bottom
triangles.Add(vt+4); triangles.Add(vt+0); triangles.Add(vt+6);
triangles.Add(vt+6); triangles.Add(vt+0); triangles.Add(vt+2);```
UVs correspond to vertices, so you'd have to show how the vertex indices correspond to the UV indices
rite there
I'm on my phone so I'm not really going to be able to analyze this properly
rite
you will need to share the entire script so that we can see how you actually use uv
!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.
Use a paste site for those of us on mobile
just to confirm.. the UV stuff is called 6 times, once for each face?
vertex
im pretty sure
im aware
im doing it
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
perhaps you need more verts then? consider.. What if one corner is upper right on one face, and lower right on another...
guh?
it is not uncomming to have more than one vert at the same location, esp if you want them to have say.. different normals
their normals are appearing fine
8 verts
they match!
let me try to put it this way... front face.. top left corner has UV 0,0 right face, top left corner has uv 0,0 so, if you use the same UV's for the top face the bottom two corners with both have uv 0,0!
i was wondering about that
I'd expect something more malformed like this
the only way for the cube not to look like that ^ is to either have a normal map that adjusts normals
or that the cube is broken into separate submesh polys
which means 4 verts per side
ah, all of their normals are -Vector3.forward
yeah i put that and it just worked out fine so idk
uv is an array of v2s that has to map 1 to 1 to the array of verts
ok
so, if two faces that "share" a vert need to hve different UV's ... you'll need to create TWO of thos verts.
it is indeed waste of memory, BUT it makes processing much faster
in order to have a hard edge where normals are not aligned there has to be 2 verts at the same point with different normals
thats just how graphics work
blender and other 3d software insulates you from that
probably because it's easy to unwrap a cube with the top and bottom removed
they manage it under the hood so you dont have to think or know about how gpu graphics actually work
that might explain why the sides are flipped actually
the way you did this just happened to work for the sides
funky stuff
yeah
Doesn't work... Thanks for your help anyways, didn't try it
so this would up me from 8 verts to 24 unfortunately
it already is 24
yep- since each of the 8 corners touches 3 faces.
no its 8 because i did it wrong
that should have visible impact on the shading of the geometry
similar to the cube Fen posted
i checked the code so i blame the visual being somewhat flat on broken/incorrect normals then
you still have to make it 24 if you want to unwrap it, because shared verts wont allow you to unwrap each face over 0-1 without distortion
https://hatebin.com/gbsonrkjqn
That's my cube in opengl
I think indices are triangles. Been a while.
By assigning normals that point out from the center of the cube, I get the expected weird smooth cube
When they all point in the -Z direction, it kind of looks right from one side
But it's nonsense from the other, since the normals are all pointing the wrong way
guess RecomputeNormals would produce same as above
the sun is pointing at the cube, but it's not lit
it's just catching environment lighting
so, yeah, you'll want to use 24 vertices -- 4 per side -- and make their normals all point in the same direction as the face's apparent normal
oh yeah I remember running into that problem
otherwise, you'll have the Weird Cube
or the Cube That Only Works From One Side
(this side has the normals pointing outwards)
also notice that half of your UV charts are mirrored horizontally
you probably don't want that
yeah
i forget which one unity expects
clockwise
i did the same order as every other face but i guess i did the back backwards somewhere
so now i gotta do it backwards on the tris too
or actually nah i get it
hold on
dear god what have i done
well im nearly there boys
oh no
i have an infinite loop problem. where do you find the console log on windows?
i can’t find the right webpage to guide
fuck i keep breaking it
ok im back to here now
https://docs.unity3d.com/Manual/LogFiles.html
All the log locations are shown here
ty
AppData\Local\Unity\Editor
i kept looking up console, because that is what it is called in mac, and it kept sending me to the wrong page
and if I want to write to the console log, I use Console.WriteLine( ?
Console is a layer between os terminal and application
basically just streams in out of term
just part of the .net api
if I have an infinite loop problem, can I use Console to actually log things to that file so I can see where my infinite loop is?
there is a simpler way tbh
you can put a breakpoint into each recent for and while
enable debugger and run until you find where its stuck
oh my god im stupid i was changing the top face for no reason
that is smart
you can actually run debugger while it is stuck in a loop, it should connect and hit it, i think
we are all wound up now boys
what does this mean?
means your code is broken and compiler cant compile it into a working executable
all compiler errors have to be fixed before you can enter playmode
check the console window to the offeding script
ok I have been using Debug.Assert to show errors. But i need to throw an actual exception
the code in your project, doesnt matter where it came from, if its broken it wont compile
something got busted for you in the install process then
it should only leave compiler errors after clear
if this is brand new and that appears
where is that?
console window, button with text Clear
bottom of the screen
would anyone know what is the right syntax to make a C# assertion that actually throws an exception? There seems to be several different Assert methods in different classes
try remove the burst package
if you read carefully the text you will figure out most errors and where they come from yourself
what you can do is open Package Manager in unity and either update this package, or remove it
first try updating
keep the console open at all times
same menu Window
wtf are you doing to need all of those using statements in one script?
i have no cle
clue
its telling me this
I'm guessing you are just letting your ide add using statements without you paying any attention. So I would recommend you remove most of them and then look at the docs to see which ones you should actually be including
i didnt add any of them
did you update the package?
through package manager?
yeah i updated everything
read what I wrote, again
click on Burst
check if there are other versions available
switch versions until it works
or, look if there are any missing dependencies
where are you seeing burst?
in the list of packages
You shouldn't be pushing the library folder. This would indicate you don't have a correct git ignore
only showing one availabe versionm
!vc
Unity Version Control
Git
Get the latest .gitignore file from here. It should be placed at the root of your Unity project directory.
@rustic copper did you create project from android template or mobile?
2d core
copy the error starting from The type or namespace.. into google
my guess is that there is a dependency missing
this should be common enough issue to find a solution, which most likely will involve getting yet another package
like AndroidToolsSomething
alternative is to remove Burst
but this will lead to a bunch of other package removals that depend on it
if you want to go through that process, removing packages until it works, try it
it is telling me to right click on my project
build the project, send zip
this line keeps getting me the error "index out of range" and not drawing my mesh
if (chunk[vx] != 0 && chunk[vx-1] == 0)
im trying to check if the voxel next to the current face is solid
Can I share it from cloud?
all voxels are stored in a list
Does that work too?
you can host it wherever you want
itch is typically the best option
just to be clear.
you are talking about sending the EXE not the Project Folder / Unity project yes
no prob! lmk if you have any q
hi sorry back again
if i wanted this block to get destroyed after going past
-6y how would i program that
i did that but it did not work
Did you actually attach this code to the block?
this should work
Then debug it
idk i thought it might be a bit low but it is out of pov
how do i debug it?
void Update()
{
Debug.Log($"Block is currently at: {transform.position}");
if (transform.position.y < -6f)
{
Destroy(gameObject);
}
}```
Or that
should i just put that under
whats that😭
oh wati
ik what inpector is
the thing that shows the components
including Transform which holds position
where should i look in it
0.89
ok but during playmode does it reach -6 ?
it wont magically know its out of the screen unless it reaches there
yeah it falls. im trying to make a game where you dodge falling obsitcals
I get it that it falls, but does it keep faling past -6
you would pool them instead for lag
i used a unity animation event and the animation is blocking mid way
ah is that easier?
instantiating and destroying is expensive
how do i do that?
it basically just disables it, resets it then enables it again
I would get ur script working first then worry about pooling
dose somone know?
make sure 100% the script is running by checking those logs
no you should probably explain what "blocking mid way means"
or show vid
is not from aniomation event
the animation just frezes at the third frame
and it stays there permanently
then you should be inspecting the Animator selected during playmode and see where its at exactly
How can i get this to work?
I basically want a class to appear in the inspector when i select a specific enum from the drop down. this is a scriptable object and it's used for level design.
WHY DO I WANT TO DO THIS? becasue if i include all feilds in every scriptable object it makes my work flow confusing to look at and it seems less organized.
WHAT IS MY SOLUTION? i want to start with one enum, make a selection, then have new enums appear below ( in inspector) relative to the previously selected enum.
This is a scriptable object but onEnable and OnDisable wont work in this case.
I need an alternate solution to do the same thing. (which essentially is just an inspector update when selecting specific enums)
public class Point
{
public Vector2Int position;
public PointState pointState;
public PointType pointType;
public D typedata = new();
public event Action<PointType> Change;
private void OnEnable()
{
Change += ChangeTypeData;
}
private void OnDisable()
{
Change -= ChangeTypeData;
}
private void ChangeTypeData(PointType pt)
{
switch (true)
{
case var x when x = pt == PointType.Shape:
typedata.data = new TypeData.ShapeType();
break;
case var x when x = pt == PointType.Dot:
typedata.data = new TypeData.DotType();
break;
default:
typedata.data = null;
break;
}
}```
this or gotta make a custom inspector script
Hi! I have a Unity project that runs very slow, and I've pinpointed this to be because the textures are huge and fill up all available VRAM. I've seen this in the memory profiler and verified that reducing the textures will solve my problem by setting the quality setting "quality mipmap limit" to very small (1/8).
I can't have a global, low quality setting though, as some of the textures need to be high res. Luckily, textures can have a max size in Unity, so I don't seem to need to adjust all assets by hand.
However, and here's my problem: the assets (which come from my client in big quantities) are glTFs, imported with glTFast. The textures are embedded and the option to set a max size are not available in Unity Editor.
Is there any way around this?
Use a gltf import asset or make your own. You can find free ones on GitHub.
You mean like an AssetPostprocessor, and reimport all glTF's? I guess that could work...
I need help. I'm currently trying to load all Scriptable Objects from a specific folder in my project, and put them all in a list, but I can't find a single good way to do it. I've heard you're never supposed to use Resources.Load, but I can't find anywhere on the internet how to do what I'm wanting to do.
Here's a copy of my code, and the issue is in "ResetDebugItems", on line 69
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.
I have no clue what's going wrong, but the folder path is indeed being obtained, and it does indeed contain Scriptable Objects, as seen here:
Does anyone know where I've gone wrong?
I want to use it for an Editor Script, where I click a button on the Debug Inventory to set all items in it to having 99 of every item in "ItemScriptables"
Is there a way to access folders that aren't in a "Resources" folder?
Should I put all of my game's assets in a resources folder, in that case? Is there any issues that would emerge from that?
I've heard common practice is to never use the "Resources" stuff, is there an alternative, if all I want to do is access things in folders for editor scripts?
Is there a way to access folders that aren't in a "Resources" folder?
No.
Should I put all of my game's assets in a resources folder, in that case? Is there any issues that would emerge from that?
100% no. Issues include: having no control over what is built into your game. Having difficulty unloading content from memory. Large build sizes with often with content duplicated and built twice.
I've heard common practice is to never use the "Resources" stuff, is there an alternative, if all I want to do is access things in folders for editor scripts?
Addressables
Or, direct references into a scene, but note there's limited control over memory with that option
Since it's editor only, AssetDatabase is an option. FindAssets + GUIDToAssetPath + LoadAssetAtPath
https://docs.unity3d.com/ScriptReference/AssetDatabase.FindAssets.html
Make sure you guard with #if UNITY_EDITOR btw, your current script won't compile due to a using and AssetDatabase calls will need the same
Thank you very much, I'll try that!
Ah, Editor scripting, missed that part. Yeah AssetDatabase is the way
Next time post in #↕️┃editor-extensions so it's clear
Sorry, I wasn't aware there was a specific channel for it. Thank you.
Presumably you are not referencing their namespace (or assembly if you're using asmdefs)
I have an admin tool (unity project) that I generate as a windows exe, zip, and send to my designer. Recently their machine (windows virus protection) started flagging it as containing a virus.. Any ideas what might be the problem? the app itself is pretty simple - it just reads/writes json files and exports a binary file to the game directory (which is specified in player prefs) - maybe that's the problem?
theres likely not much you can do about it, the file operations could most definitely be a cause. easiest thing is just to tell them to run it anyways. Otherwise you're gonna have to try uploading it via some other method, maybe as a web app if possible?
nah, web app won't work here since the admin tool has a feature to export the addressable (ie, the content "save file") directly to the unity assets/addressables directory.. I'm seeing if I can go through this microsoft malware false-positive portal thing but it's a pretty invasive process (ie, asking for the build definition, the detection name, versions of windows and windows defender - all of which is kind of a pain because it's not flagging on my machine, so I have to ask the user to get me all this stuff)
what does the library folder contain?
I imagine the windows defender process is identifying it as a virus since it's doing things outside of it's own directory sandbox
Maybe just tell them to add the build to some excluded folder, and only download these builds to that specific folder
every other solution would be a pain, not sure how much you're trying to go through to fix a 30 second issue on other peoples pc
yeah.. well, I was just hoping it was something trivial like .. including symbols or using a development build
https://www.microsoft.com/en-us/wdsi/filesubmission?persona=SoftwareDeveloper
this page is the best I could find but I can't really imagine MS/windows is going to literally review an app that changes as often as my admin tool does (like every day!) and/or .. add some whitelist checksum? to windows defender or whatever for it without honestly knowing what the app is doing
Submit suspected malware or incorrectly detected files for analysis. Submitted files will be added to or removed from antimalware definitions based on the analysis results.
maybe someone else has a magic workaround that i am unaware of 😄. i imagine any real workarounds would be easily abusable by malware though
Hate to state the obvious, but are you sure it's a false positive? Upload it to one of those multiple av scan sites and scan your system. Some types of virus infect executables and DLLs on your system indiscriminately
... i wrote the code, so.. yes? 😛
that's meaningless if you are the one infected
https://support.microsoft.com/en-us/windows/add-an-exclusion-to-windows-security-811816c0-4dfd-af4a-47e4-c301afe13b26
this would definitely be a lot easier and shouldnt be hard for anyone to setup, assuming this isnt some large scale tool that a ton of people are using. an excluded folder will not check anything inside
what xEvilReeperx is saying is also valid, maybe some external malware found its way in
Yeah - I think the exclusion is appropriate although I'm not sure if the exclusion is going to "stick" because I'm doing new builds quite often (and I imagine that the checksum or however it identifies a given process would change from day to day).
It's pretty unlikely that my system is infected and causing a downstream identification of a virus in the software.. like, if my system were infected, the "transmission vector" would be completely different than me writing software, compiling it into a windows build, and sending that to a coworker. I understand the idea that my machine could be infected, but that transmission chain is unlikely
it says it applies to subfolders, so people can download the build into that 1 excluded folder
it definitely isnt a large scale solution
Ah, that's cool.. I didn't see that bit, I assumed you had to add an exclusion for a specific exe
havent used it personally in this case so I hope it works like it says 😅
have you ever used this before?
if you're having an issue post code + ask. I've used it extensively and it works fine
It's pretty standard around here
public class NewBehaviourScript : MonoBehaviour
{
public TextAsset ta;
// Start is called before the first frame update
void Start()
{
ta = new TextAsset();
Debug.Log(ta.text);
}
// Update is called once per frame
void Update()
{
}
}
So I have this code that I dragged a text file to but it does not show "hello" or "hello world" (text also has the word, not just file name). what am I missing?
here is panel:
output:
hmm can you show contents of helloWorld?
you are doing new()
don't do that.
you're telling it " I want a new object instead" hence why its blank
I'm not sure how to fix this problem. I can't seem to clear the dictionary without first creating it, but I want to clear it if the function gets run again
thank!
declare the new() dictionary at the class level this way you dont create a new one each time
Like this?
yes, the null check is prob not needed. You probably want to replace it with itemDicionary.Count > 0
clear
How could I figure out which ones are under it? This is what I tried doing but it doesnt work: https://hastebin.com/share/sojohekima.csharp
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
once you capture all of them in the radius, from the overlapsphere you just loop over everything found and do something like
Vector3.Angle((objPos - center).normalized, Vector3.up)
to get what angle each object is at
Thank you, how can I check if the two angles are similar rather than equal?
what do you mean by similar? that sounds like the same thing . . .
within a range of each other?
you would choose how close is close enough
because currently I am using if (angle1 == angle2) {do stuff} but I want to do something like if (angle1 ≈≈ angle2) {do stuff}
you have to decide how close is close enough
Within a range of a few degrees I guess.
Since they are almost never going to be the exact same.
if ts just about highlighting things as line goes by, think i might just InverseLerp it, that way i get a nice fade in then fade out
whats that ≈
can you just use mathf.approx ?
I didnt know that existed
can also just do multiple comparisons
greater then angle - 3 and less than angle + 3 for example
or even better Mathf.Abs
Mathf.Abs(angle1 - angle2) <= 3f for example
subtracting one from the other tells you how different the numbers are, Abs removes the sign from that so you can do a simple comparison and tell it how close is close enough for your purposes
Keep in mind you might need to deal with angles wrapping.
iirc for this use case should be pretty contrained in the 360
Oh, also, I have discovered a problem where the rotation of the object position angle is always positive, but the rotation of the line on the radar is either positive or negative.
Just subtract the angles and check if that value is less than a tolerance . . .
Get the absolute value of the result to compare against a positive value . . .
Oh shit, exactly!
I use an extension method for that . . .
i generally just write it out, less for co workers to have to go to def and look at
I am having a problem where for some reason even when the angles are obviously within 3 degrees of each other, it still wont return true.
Who doesn't love a mystery? 😄
I debugged to check if it returned true and it never does
i would look at that rotation values in the log
one might be reporting the equivalent negative angle
Oh wait, I might know why, one sec.
for some reason ray.transform.rotation.y is returning a value between 1 and -1.
rather than a degree
yeah you want the euler angles for the rotation
transform.rotation.eulerAngles.y
rotation is a Quaternion, so the x, y, z, and w components do not do what you think they do
question on some method structuring. Let's say I have this class for the UI which is handled via dependency injection, so technically I shouldn't be using an instance that's flagged unassigned and to prevent that I am constantly adding some sort of check every time you call these methods. I was just wondering if there's a way in c# that I can create a requirement to call a check comparison by tagging methods with an attribute or such.
It's not so much a problem of checking this assignment in each method, it's that I am sometimes calling this method multiple times because some of these methods are used by each other.
private bool IsSlotTypeCompatable(EquippableItem equippable, int slotIndex)
{
if (!IsAssigned) return false;
if (IsSlotEmpty(slotIndex)) return false;
}
public override bool IsSlotEmpty(int index)
{
if (!IsAssigned) return false;
}```
Like here as an example I check the assignment twice.
the check is just checking a boolean
i feel anything you are asking about to skip it would be more complicated
like you mentioned attributes well the only way to access attributes is via reflection
yeah I guess it's not that big of a problem as for performance, but it feels kinda messy
having some attribute to say hey method, check if the assignment is flagged and only once
Is the question about performance or about code duplication?
if this was a other language i would prolly use decorators
mostly code duplication
Because yeah, performance of checking a boolean is pretty irrelevant.
really its easy enough to read
Do you need to check the assignment if you are calling IsSlotEmpty?
does not hit perf
clearly shows the function will bail early in these cases
seems fine
A few things to think about:
- Is it caller's responsibility to check
IsAssigned, or is it the method's responsibility? - Is it possible for
IsAssignedto change depending on when the method is called?
some code duplication is fine, if it avoids further complexity
in that case probably not, but this was just an example. The idea is I shouldn't be calling any of these methods if they were unassigned, and furthermore this falls into another problem I have and that's figuring out where and how much I should be null checking, haha
would not add complexity in service of making it dry
The easiest way is to just make the methods not callable unless it's already assigned.
the guard statements are already a huge upgrade from how most new people with do it with nested ifs
True, I wouldn't call the method if it was null . . .
it's some UI stuff that im trying to decouple but stick to a DI approach for reusability
but yeah, ideally I shouldn't be calling these methods if they aren't assigned in the first place
!ban 596888328050180106 bot
minesniffer was banned.
does somebody know what the problem is? im trying to make that whenever you hold r you restart the scene while it gets darker and darker with a gameobject that just gets more opaque with time
@swift falcon Please don't crosspost. Stay in one channel #💻┃code-beginner
Yeah those methods obviously sit in a class, so make that class has to be constructed with things already assigned, and methods wouldn't need to do all these checks.
Start with posting the error message. That's kind of a big deal . . .
That way you essentially moved the checks to compiler: the mere fact that you have access to an instance of that class means it's already assigned and no check needed.
Try and use Google and post the translation . . .
it says something by the lines of: you cant modify the given value of " spriterenderer.color" because its not a variable
Kinda hard without knowing what the error is saying . . .
Now that makes more sense . . .
(sorry for the ghost pings) That's fixed now, but I have discovered a new issue. The script is oddly creating the instances when the line is not at the same spot, it also is creating around 15 instances every time. Here is my script. Here is a video
You cannot assign the alpha of a Color because it is a struct. You need to copy the SpriteRenderer Color to a local variable, update the alpha value, then assign the local variable back to the SpriteRenderer color . . .
lemme procces it kewk
got it i think
ill update if it worked!
i have the same issue
i created a float that is "blackscreening", made it equeal to "blackScreenSpriteRend" and then modified "blackScreening" and then made it equal again (after modifying it) to "blackScreenSpriteRend.color.a"
maybe im just not looking at it from the right perspective
I believe the cause of the problem is that the eulerangles of the radar line is always a value between 0 and 360, but the Vector3.Angle can only return a value between 0 and 180, so when it reaches 180 and you keep going, it just flips the direction of change.
I think this is causing the values to be both flipped and mirrored.
is there a version of Vector3.Angle that returns a value between 0 and 360 instead?
yeah its that error
yes
but idk how to change it
did you see example on the link ?
Color color = blackScreenSpriteRend.color;
color.a = somevalue;
blackScreenSpriteRend.color = color;```
part 1
and here is the other thing
the whole struct?
color is a struct
and what is a struct?
its a value type object
and what do you mean with copy the whole struct?
Irrelevant at this point. But it is like a class, but instead of a reference type, it is a value type (as nav said)
Which means you deal with COPIES of them, instead of actually modifying the actual object itself
did you see the example i sent also?
Remove the .a at the end here
#archived-code-general message
yes but i didnt understand it
which part confuses you
lemme see again
that you dont write .color.a but then under it you make color.a = somevalue
and later on dont use it again
i make a copy of color, change the alpha value and put the copy back
so by removing the .a which is the opaque level you select rgba?
No
Color CONTAINS alpha
Alpha is what you called "opaque level" btw
thats what i mean
the whole struct is Red Green Blue Alpha
thats what i meant with rgba
It includes those, yes
ys but alpha is a read only property you cannot directly assign it
but i only want to mess with the Alpha because i want to keep it an exact color
doesnt that mess with the RGB?
No, not at all
uhh no because you're copying the same values
(just asking for reasoning behind it, not questioning your knowledge)
you're only changing .a
Because you are copying the WHOLE state. Changing ONLY alpha, then putting it back
what is var color?
Since only a is touched, only a is changed
just a random name right ?
Same as Color color
yes its just a name that made sense
okey
you can use whatever u want
lemme procces
so in my code it would be something like
public color BlackScreenSpriteRend.color
not at all no
dayum
That is simply not how a variable is created
this is meant to be a local variable
so its disposed once you did what you needed (assign it to color)
[Accessor] [Type] [Name you make up]
i saw it
hmmm lemme think rq
so i can just make/write/create it inside the function?
yes
no, hover over the color it tells you the type
why not?
because it doesn't exist?
No references in a variable declaration (there is qualification, but I don't want to confuse things here)
okay
the type of what?
variable?
Type has a specific meaning. A class name is a type. A struct name is a type. Enum names are types
and they're all objects, hence OOP
what is oop?
Object Oriented Programming
Object Oriented Programming
you kinda need to learn these things to code in c#
with this as a base
yeah im learning unity/c# at the same time
there isn't much to think about
but mainly focusing in c#
its literally the same thing I've sent, only mine had var out of habit but you can replace it with color. Ill do that now
so i could have writed color color
and set that color to blackScreenRend.color?
and then somehow modify color.a
mate, c# is case sensitive
color color isn't valid
Color color would work
color screen could also work?
epic
Color color = blackScreenSpriteRend.color;
color.a = somevalue;
blackScreenSpriteRend.color = color;
im just reposting so i dont have to scroll
yes but obv replace somevalue with whatever you need to put there
Color Screen = blackScreenSpriteRend.color;
sure
but if i write color.a how does it know to change the color.a of a specific gameobject?
thats what i was missing
how to tell the exact game object that i want to change color.a
you cannot use color outside the method if its a local variable
just make a copy each time you want to change it
is it better to create it as a local variable or as one outside?
a copy?
so it takes color.a as the color.a of "blackScreenSpriteRend.color because its the only one available inside that function?
or why
srry if im getting on your nerves im kinda slow
nah no worries
and i also need to traduce everything in my head to a different language
so its set up to confusion
because its a struct you only deal with copies, and alpha is a property of that struct that is read only
it cannot be changed from outside
it can only be read?
i understand ( i think) that color is a struct and it has property´s inside as Alpha
ohhh
yes
well color property is actualy set and get props
you'd have to learn properties, but in a nutshell they are special keywords for a variable to run a method when the value is read/set
for a variable to run a method?
i dont know if im dealing with some strange thing that is outside of my actual capacities or i just aimed how to answer my problem in a very weird way
you're just overthinking it and missing a couple of basics c#
prolly
i try to understand why and how it works but im unable
kewk
Color color = blackScreenSpriteRend.color;
color.a = somevalue;
blackScreenSpriteRend.color = color;
Color color
Color is a type of variable and color is the name
i set that color is equal to "the color of "blackScreenSpriteRend.color""
so where is the confusion
im trying to procces it
wait
im explaining my thought procces so maybe it can help you help me
"this temporary variable called color of type Color will be copy of the current blackScreenSprite color"
color.a = whatever i need the opaque level to be
OHH
I GOT IT
I GOT IT
since color was the name of the Color you say color.a for reffering to the color
not to a color
to THE color
i was reading it like this
Color otherWordThatIsntColor = blackScreenSpriteRend.color;
color.a = somevalue;
blackScreenSpriteRend.color = color;
so in case that i read that like that the only thing i had to change is this
oh, that would give you an error as it wouldn't know what color is
Color otherWordThatIsntColor = blackScreenSpriteRend.color;
otherWordThatIsntColor.a = somevalue;
blackScreenSpriteRend.color = color;
thats the error that my mind was having
kewk
omg it was so simple
yes lol
im to happy to understand it
im just dumb
i forgot that by saying otherWordThatIsntColor.a is the same as saying color.a for that variable
so i was trying to understand how to add that strange and weird separated and isolated "color.a" to the otherWordThatIsntColor
idk if you understand it
just wanted to point out how dumb i am
kewk
yes just remember this is making a copy , hence why it needs to be assigned back to the color
if you modified it and not assigned it back it would just be modifying a copy
yes
its something like this
the vector is just a copy
and you modify the vector
and then make the vector equal to the transform
yes p is just a copy, you modify it then put it into it as new value
np 🙂
sweet!
do you remember something about particles and dont knowing how to call them?
that was me in case you remember
oh I think I suggested Emit(). ?
did emit work though i never seen the follow up
because right after emit(). there was a destroy(GameObject);
yep
oh haha yea thats never good
so it emited but it instantly destroyed the game object