#archived-code-general

1 messages · Page 284 of 1

lean sail
#

You can raycast, either from the camera or player depending on the type of game it is. Putting an interact script on the vehicle is kinda vague. Yea the vehicle is gonna need some script so you can actually move it but the vehicle itself doesnt need a script where it checks if the user is trying to get in

plucky dagger
#

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

twilit scaffold
#

Turning off "Show new snippet experience" solved this issue, so far.

swift falcon
#

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?

vagrant blade
#

Nope, navmesh plus is it really

versed spade
#
    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.

tardy crypt
#

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?"

gusty aurora
#

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 ?

versed spade
pliant sapphire
#

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

hard viper
#

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

delicate flax
hard viper
#

does it actually write a file

hard viper
pliant sapphire
#

wait

#

how

delicate flax
#

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    
    }
pliant sapphire
#

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

pliant sapphire
brisk plaza
#

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?

delicate flax
# pliant sapphire i dont have gameManager and it doesnt have state in it im confused

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;    
}
pliant sapphire
#

Okay I will do that thanks

weary swift
#

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.

tardy crypt
versed spade
tardy crypt
#

Sounds reasonable.

versed spade
#

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.

leaden ice
versed spade
#

oh, should I move everything in update to FixedUpdate?

leaden ice
#

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

versed spade
leaden ice
#

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

versed spade
#

So aslong as the rotation and other items are in fixed Update its good to go?

versed spade
# leaden ice You're also mixing Rigidbody motion with Transform rotation

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.mehttps://www.reach.me/xenfinity

Hey developers,

Bilal here, and In this video, I'm excited...

▶ Play video
leaden ice
#

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

versed spade
#

Would the ridgebody method for that be SetRotation?

leaden ice
#

You'd apply an angular velocity, use AddTorque, or MoveRotation

#

Check the docs for Rigidbody

versed spade
#

gotcha

pliant sapphire
#

I added this to code as u said btw

delicate flax
pliant sapphire
#

ahh okay ty

#

this was that save

tough obsidian
#

hi actually i am getting null reference error but can't understand why it is happening

rain minnow
heady iris
#

you have cropped out all of the line numbers

tough obsidian
rain minnow
#

that's the only variable on the error line . . .

tough obsidian
pliant sapphire
#

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...

leaden ice
heady iris
pliant sapphire
pliant sapphire
swift falcon
#

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.

pliant sapphire
#

save debug doesnt show and load wont show because of this error

#

which occured after I deleted my .json file

leaden ice
#

click on it, read the full error message
Find the filename and line number where it's happening

opaque fox
#

I am trying to figure out how i reference the object my script is attached to in a public variable ?

pliant sapphire
#

goes here

leaden ice
pliant sapphire
leaden ice
#

you'

#

re trying to read a file that doesnt exist

#

so it's throwing an exception

pliant sapphire
#

yes but cause I deleted it

#

but it should make new one everytime I save

leaden ice
#

Well your code expects it to bne there

pliant sapphire
#

and then rewrite it after I save again

leaden ice
#

so you need to make your code able to handle the possibility of the file not being there

opaque fox
leaden ice
#

I guarantee it

#

explain the scenario.

pliant sapphire
leaden ice
#

i.e. check if the file exists before you try to read it

opaque fox
#

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

vivid heart
#

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?

opaque fox
#

it is a weird work around i know

pliant sapphire
leaden ice
leaden ice
pliant sapphire
leaden ice
#

you're trying to read it before you write

pliant sapphire
leaden ice
opaque fox
pliant sapphire
#

I first save and then I click load

leaden ice
leaden ice
#

which can refer to objects inside the prefab no problem

pliant sapphire
#

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

leaden ice
pliant sapphire
#

how can i make my button find reference to SaveJson func

opaque fox
pliant sapphire
leaden ice
leaden ice
# pliant sapphire

you need to drag the object that has the script into that slot, then assign the function

leaden ice
#

I will help you with the best way

opaque fox
#

of what

leaden ice
#

and the spawner thing

#

like - explain your situation better.

opaque fox
#

k 1 sec

pliant sapphire
#

you get what im saying?

leaden ice
#

Attach a different script to the button with this code:

public void Save() {
  SaveServiceSystem.instance.Save();
}```
#

and assign that in the button inspector

sick silo
#

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?

pliant sapphire
opaque fox
#

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

sick silo
cosmic rain
sick silo
#

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

tawny elm
#

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?

delicate flax
#

make it a list instead I guess

#

List<Vector3> vertices = new ();

hard viper
#

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? ?

tawny elm
#

instead its an array

#

cuz im doing this
MeshFilter.vertices = vertices

delicate flax
#

then run, vertices.ToArray(); when you assign it.

tawny elm
#

mk

void basin
#

i am planning to learn C# but i want to only learn the essentials. does anybody know a simple and short tutorial

tawny elm
delicate flax
# void basin i am planning to learn C# but i want to only learn the essentials. does anybody ...

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/

···································...

▶ Play video
void basin
#

i dont necessarily need one that goes into many details, but gives broad context

hard viper
#

maybe C# discord knows more

knotty sun
hard viper
#

that isn’t really helpful

knotty sun
#

wasn't meant to be, the question itself was nonsensical

hard viper
#

it isn’t nonsensical

#

he needs an intro to C#, focusing on syntax, given he already understands basic programming

knotty sun
rigid island
swift falcon
#

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.

swift falcon
reef garnet
#

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

reef garnet
#

Thank you, I did just find a solotion with the SetColor method

tawny elm
#

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) );}```
fervent furnace
#

this always returns 0

tawny elm
red mango
#

is there anyone thats really good at creating 2d platformers or games here if so could u dm me

tawny elm
#

i dont know why Random.Range(0, 1) only returns zero

heady iris
#

because you gave it integers

mellow sigil
#

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

heady iris
#

they expected the behavior it has with float arguments

tawny elm
#

rite

heady iris
#

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

tawny elm
#

so its just returning 0.48549 or something instead of just 0s and 1s

mellow sigil
#

no, it's returning exactly 0

tawny elm
#

because it rounds it down?

mellow sigil
#

no

#

because Random.Range(x, y) returns a value between x and y - 1

heady iris
#

as compared to how it behaves with ints

mellow sigil
#

are they?

heady iris
tawny elm
#

i thought maybe its because its doing a range between floats instead of between ints like i want it to

heady iris
#

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

fervent furnace
#

the chunk is list<int> so changing it to float overload doesnt help

tawny elm
#

so would Random.Range(0, 2) return 0s and 1s?

heady iris
#

If you want to get integers in the range [0, 1], then do Random.Range(0, 2)

#

Correct.

heady iris
tawny elm
#

i feel like you couldve explained that way easier

heady iris
#

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)

tawny elm
#

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

heady iris
#

check the numbers you're getting!

tawny elm
#

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

heady iris
#

show your new code

tawny elm
#
  {chunk.Add( Random.Range(0, 2) ); Debug.Log(chunk[i]);}```
heady iris
tawny elm
#

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

weary swift
#

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.

weary swift
#

I know that it is possible to implement animations in code. What should I use, code based or graph based ?

weary swift
#

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 ?

gusty aurora
#

Added bonus of controlling how many you get of each

fervent furnace
#

i prefer range(0,2)

#

keep in mind the range is [a,b)

knotty sun
#

@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

tawny elm
#

the problem was over like 10 minutes ago

rigid island
weary swift
#

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

rigid island
weary swift
#

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

weary swift
icy depot
#
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?

rigid island
#

na

#

you should need base
public Foo() : base()

weary swift
#

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

rigid island
#

also most of those can be a simple blend tree

#

Idle,walk,running,Spriting

weary swift
#

Not in this case because of how the movements works, but I know about blend tree 👍

weary swift
rigid island
weary swift
#

I just thought about it, I guess you can use a blend tree for this

#

I'm gonna do it

icy depot
vivid heart
#

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?

rigid island
rigid island
heady iris
#

I tried to read the readme and woke up 74 hours later in a field

rigid island
#

I'm too used the asp.net DI system, I'm frightened to try anything else lol

gray mural
#

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?

leaden ice
#

This is indeed pointless

vivid heart
gray mural
#

So no visible changes are noticeable for the player, right?

leaden ice
#

No

gray mural
leaden ice
#

The game isn't rendered until the end of the frame

#

How would they notice anything

gray mural
#

Got it, thank you

#

just wanted to make sure

heady iris
placid obsidian
#

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 hmjj

leaden ice
heady iris
#

yeah, that's not a spanning tree at all

placid obsidian
#

I'm sampling the rooms rather than doing every single one

heady iris
#

if you just want the longest path, you'll need to compute all-pairs distances

leaden ice
#

Also I'm unclear what you're asking. Are you trying to get a path from a to b?

heady iris
grand hare
#

how do i edit stuff that is greyed out like that?

heady iris
leaden ice
heady iris
#

create a new material and use that.

#

this is also not a code question

grand hare
#

oh shit i fixed it way easier mb

#

i jst dragged on my new matterial

leaden ice
#

Yes that's called using a different material as suggested

placid obsidian
leaden ice
#

Like ticket to ride longest train?

placid obsidian
#

yeah

leaden ice
#

Or Catan longest road

placid obsidian
#

ticket to ride longest train sounds about right

leaden ice
#

Iterate through each node in your tree and do a DFS from each. Pick the one that reached the greatest depth

wooden trail
#

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?

placid obsidian
#

it did sound like dfs was what i'd be after! good to know i was on the right track somewhat, thanks happ

leaden ice
#

"change the texture" is vague and doesn't sound like a code question unless you mean changing the texture of something in code

wooden trail
placid obsidian
wooden trail
grizzled ferry
#

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?
heady iris
#

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)

grizzled ferry
knotty sun
grizzled ferry
knotty sun
#

the latest is 2022.3.21f1

grizzled ferry
grizzled ferry
eager steppe
#

I Broke Hold Notes. Again.

hard viper
#

can you serialize a MyEnum? as a nullable type?

clever lagoon
eager steppe
hard viper
#

i am asking

clever lagoon
rigid island
#

why

eager steppe
#

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

hard viper
#

i am making a hierarchy of enums, and need a way to indicate “this thing has no parent”

clever lagoon
#

you'll need to make that one of the enums

rigid island
#

why not just a value of NULL for enum itelf

#

anyway you can do it iirc anyway

#

since they are value types

hard viper
#

how do you set a null value for a value type tho

rigid island
#

public MyEnum? Enum;

#

Enum = null

rigid island
#

yup x2 on that

leaden ice
#

Nullable type is of course an option too, it's equivalent to using a separate bool variable

hard viper
#

damn. I did a big dumb when I defined this thing a long time ago LOL

rigid island
#

any value type can be made nullable with ?

clever lagoon
#

ya, that works- dammit nav, now I need to learn how those guys get serialized!

rigid island
#

spoiler alert : in unity they dont

clever lagoon
rigid island
#

probably , havent tried

#

I know it works for Json, i dont see why it wouldnt

tawny elm
#

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));
leaden ice
tawny elm
# leaden ice 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);```
leaden ice
#

UVs correspond to vertices, so you'd have to show how the vertex indices correspond to the UV indices

tawny elm
#

rite there

leaden ice
#

I'm on my phone so I'm not really going to be able to analyze this properly

tawny elm
#

rite

heady iris
#

you will need to share the entire script so that we can see how you actually use uv

tawny elm
#

bloody hell

#

o it actually embeds that handy that

spring creek
#

!code

tawny elkBOT
spring creek
#

Use a paste site for those of us on mobile

clever lagoon
#

just to confirm.. the UV stuff is called 6 times, once for each face?

spring creek
tawny elm
#

im doing it

clever lagoon
# tawny elm vertex

perhaps you need more verts then? consider.. What if one corner is upper right on one face, and lower right on another...

tawny elm
#

guh?

clever lagoon
#

it is not uncomming to have more than one vert at the same location, esp if you want them to have say.. different normals

tawny elm
#

their normals are appearing fine

ashen yoke
#

how many verts in that cube?

#

there has to be equal amount of uvs

tawny elm
#

8 verts

heady iris
#

they match!

ashen yoke
#

you think?

#

looks to me that the cube is hard edged

#

meaning 4 per side

clever lagoon
#

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!

heady iris
#

I'd expect something more malformed like this

ashen yoke
#

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

tawny elm
#

is that anything to do with the UVs tho

#

the noramls look fine in engine

heady iris
#

ah, all of their normals are -Vector3.forward

tawny elm
#

yeah i put that and it just worked out fine so idk

ashen yoke
#

uv is an array of v2s that has to map 1 to 1 to the array of verts

tawny elm
#

ok

clever lagoon
# tawny elm ok

so, if two faces that "share" a vert need to hve different UV's ... you'll need to create TWO of thos verts.

tawny elm
#

that sounds cringe and silly

#

how does the other sides work out fine then

clever lagoon
#

it is indeed waste of memory, BUT it makes processing much faster

ashen yoke
#

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

heady iris
ashen yoke
#

they manage it under the hood so you dont have to think or know about how gpu graphics actually work

tawny elm
heady iris
#

the way you did this just happened to work for the sides

clever lagoon
#

try it with a UV map texture, and it should be illuminated. lemme find one for ya

tawny elm
#

funky stuff

clever lagoon
#

heh, cool!

#

notice the different orientations

tawny elm
#

yeah

grizzled ferry
tawny elm
#

so this would up me from 8 verts to 24 unfortunately

ashen yoke
#

it already is 24

clever lagoon
#

yep- since each of the 8 corners touches 3 faces.

tawny elm
ashen yoke
#

that should have visible impact on the shading of the geometry

#

similar to the cube Fen posted

tawny elm
#

i dunno man

#

theres definitely 8 vertices

ashen yoke
#

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

tawny elm
#

im aware

#

thats what i am doing

#

as we have discussed

latent latch
#

I think indices are triangles. Been a while.

heady iris
#

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

ashen yoke
#

guess RecomputeNormals would produce same as above

heady iris
#

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

latent latch
#

oh yeah I remember running into that problem

heady iris
heady iris
#

(this side has the normals pointing outwards)

#

also notice that half of your UV charts are mirrored horizontally

#

you probably don't want that

tawny elm
#

got it all working but the backs arent being rendered

#

not super sure why

ashen yoke
#

winding order

#

most likely

tawny elm
#

yeah

heady iris
#

i forget which one unity expects

tawny elm
#

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

hard viper
#

i have an infinite loop problem. where do you find the console log on windows?

#

i can’t find the right webpage to guide

tawny elm
#

fuck i keep breaking it

tawny elm
hard viper
#

ty

ashen yoke
#

AppData\Local\Unity\Editor

hard viper
#

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( ?

ashen yoke
#

Console is a layer between os terminal and application

#

basically just streams in out of term

#

just part of the .net api

hard viper
#

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?

ashen yoke
#

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

tawny elm
#

oh my god im stupid i was changing the top face for no reason

hard viper
#

that is smart

ashen yoke
#

you can actually run debugger while it is stuck in a loop, it should connect and hit it, i think

tawny elm
#

we are all wound up now boys

hard viper
#

oh god i see now the problem

#

ty cache.

rustic copper
#

what does this mean?

ashen yoke
#

means your code is broken and compiler cant compile it into a working executable

latent latch
#

all compiler errors have to be fixed before you can enter playmode

rustic copper
#

but i havent made any code

#

i only downloaded unity like 30 minutes ago

rigid island
rustic copper
hard viper
#

ok I have been using Debug.Assert to show errors. But i need to throw an actual exception

ashen yoke
#

the code in your project, doesnt matter where it came from, if its broken it wont compile

ashen yoke
#

press Clear in console

rigid island
ashen yoke
#

it should only leave compiler errors after clear

rigid island
#

if this is brand new and that appears

rustic copper
ashen yoke
#

console window, button with text Clear

rustic copper
#

here?

ashen yoke
#

where did you take the last screenshot?

#

with red text

rustic copper
#

bottom of the screen

ashen yoke
#

click on it

#

should open console panel

rustic copper
hard viper
#

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

rustic copper
#

this one stays?

#

after i click clear

ashen yoke
#

yeah

#

so this is the error that comes from the package com.unity.burst

rigid island
ashen yoke
#

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

rustic copper
#

where is package manager

#

sorry im new to this

ashen yoke
#

same menu Window

rigid island
rustic copper
#

just checking

#

i would put it under

#

unityeditor.android yeah?

knotty sun
# rustic copper

wtf are you doing to need all of those using statements in one script?

rustic copper
#

clue

#

its telling me this

knotty sun
#

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

rustic copper
#

i didnt add any of them

ashen yoke
#

through package manager?

rustic copper
#

yeah i updated everything

knotty sun
rustic copper
ashen yoke
#

click on Burst

#

check if there are other versions available

#

switch versions until it works

#

or, look if there are any missing dependencies

rustic copper
#

where are you seeing burst?

ashen yoke
#

in the list of packages

quartz folio
#

You shouldn't be pushing the library folder. This would indicate you don't have a correct git ignore

rustic copper
quartz folio
#

!vc

tawny elkBOT
#
Using version control in Unity

Unity Version Control

git Git

Get the latest .gitignore file from here. It should be placed at the root of your Unity project directory.

ashen yoke
#

@rustic copper did you create project from android template or mobile?

rustic copper
#

2d core

ashen yoke
#

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

rustic copper
#

it is telling me to right click on my project

swift falcon
#

I got a question.

#

How do I share my project?

rigid island
tawny elm
#

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

swift falcon
tawny elm
#

all voxels are stored in a list

swift falcon
#

Does that work too?

rigid island
#

itch is typically the best option

swift falcon
#

Never heard of it...

#

I'll see.

rigid island
# swift falcon I'll see.

just to be clear.
you are talking about sending the EXE not the Project Folder / Unity project yes

swift falcon
#

I meant the whole project.

#

To work together.

rigid island
#

then you need version control

#

got a quick setup vid if you need too

swift falcon
#

I need it.

#

Very appreciated.

rigid island
swift falcon
#

👍

#

Thanks man.

rigid island
rustic copper
#

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

wide dock
rigid island
wide dock
#

Then debug it

rigid island
#

also are you sure -6 is what you want?

#

try not to use magic numbers

rustic copper
rustic copper
wide dock
#
void Update()
{
  Debug.Log($"Block is currently at: {transform.position}");
  if (transform.position.y < -6f)
  {
    Destroy(gameObject);
  }
}```
rigid island
#

cant you just look at the inspector?

#

lol

wide dock
#

Or that

rustic copper
rustic copper
#

oh wati

#

ik what inpector is

rigid island
#

including Transform which holds position

rustic copper
#

where should i look in it

rigid island
#

during play

rustic copper
#

0.89

rigid island
#

it wont magically know its out of the screen unless it reaches there

rustic copper
rigid island
rustic copper
#

yeah

#

i wanted them to get deleted to stop lag

rigid island
#

you would pool them instead for lag

unique delta
#

i used a unity animation event and the animation is blocking mid way

rustic copper
rigid island
#

instantiating and destroying is expensive

rustic copper
rigid island
#

I would get ur script working first then worry about pooling

rustic copper
#

yeah ill probably try other parts of the script first

#

then come back to it

rigid island
rustic copper
#

im giving up for the night im hard stuck

#

thanks for your help though

rigid island
#

or show vid

unique delta
#

is not from aniomation event

unique delta
#

and it stays there permanently

rigid island
faint hornet
#

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;
    }

  }```
wind needle
#

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?

cold parrot
wind needle
indigo verge
#

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.

#

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"

indigo verge
# quartz folio https://unity.huh.how/programming/resources/resources-folder

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?

quartz folio
#

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

mossy snow
indigo verge
#

Thank you very much, I'll try that!

quartz folio
#

Ah, Editor scripting, missed that part. Yeah AssetDatabase is the way

indigo verge
#

Sorry, I wasn't aware there was a specific channel for it. Thank you.

quartz folio
#

Presumably you are not referencing their namespace (or assembly if you're using asmdefs)

modern creek
#

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?

lean sail
modern creek
#

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)

static matrix
#

what does the library folder contain?

modern creek
#

I imagine the windows defender process is identifying it as a virus since it's doing things outside of it's own directory sandbox

lean sail
#

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

modern creek
#

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

lean sail
#

maybe someone else has a magic workaround that i am unaware of 😄. i imagine any real workarounds would be easily abusable by malware though

mossy snow
#

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

modern creek
#

... i wrote the code, so.. yes? 😛

mossy snow
#

that's meaningless if you are the one infected

lean sail
# modern creek https://www.microsoft.com/en-us/wdsi/filesubmission?persona=SoftwareDeveloper t...

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

modern creek
#

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

lean sail
#

it definitely isnt a large scale solution

modern creek
#

Ah, that's cool.. I didn't see that bit, I assumed you had to add an exclusion for a specific exe

lean sail
#

havent used it personally in this case so I hope it works like it says 😅

faint hornet
mossy snow
#

if you're having an issue post code + ask. I've used it extensively and it works fine

latent latch
#

It's pretty standard around here

dark kindle
#
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:

rigid island
#

you are doing new()

#

don't do that.
you're telling it " I want a new object instead" hence why its blank

indigo verge
#

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

dark kindle
rigid island
rigid island
# indigo verge Like this?

yes, the null check is prob not needed. You probably want to replace it with itemDicionary.Count > 0
clear

dense estuary
#

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

quaint rock
#

to get what angle each object is at

dense estuary
rain minnow
#

within a range of each other?

quaint rock
#

you would choose how close is close enough

dense estuary
#

because currently I am using if (angle1 == angle2) {do stuff} but I want to do something like if (angle1 ≈≈ angle2) {do stuff}

quaint rock
#

you have to decide how close is close enough

dense estuary
#

Since they are almost never going to be the exact same.

quaint rock
#

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

dense estuary
#

approximately

rigid island
#

can you just use mathf.approx ?

dense estuary
#

I didnt know that existed

quaint rock
#

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

chilly surge
#

Keep in mind you might need to deal with angles wrapping.

quaint rock
#

iirc for this use case should be pretty contrained in the 360

dense estuary
#

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.

rain minnow
#

Get the absolute value of the result to compare against a positive value . . .

quaint rock
rain minnow
#

I use an extension method for that . . .

quaint rock
#

i generally just write it out, less for co workers to have to go to def and look at

dense estuary
#

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.

rain minnow
dense estuary
#

I debugged to check if it returned true and it never does

quaint rock
#

one might be reporting the equivalent negative angle

dense estuary
#

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

quaint rock
#

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

latent latch
#

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.
quaint rock
#

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

latent latch
#

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

chilly surge
#

Is the question about performance or about code duplication?

quaint rock
#

if this was a other language i would prolly use decorators

latent latch
#

mostly code duplication

chilly surge
#

Because yeah, performance of checking a boolean is pretty irrelevant.

quaint rock
#

really its easy enough to read

rain minnow
quaint rock
#

does not hit perf

#

clearly shows the function will bail early in these cases

#

seems fine

chilly surge
#

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 IsAssigned to change depending on when the method is called?
quaint rock
#

some code duplication is fine, if it avoids further complexity

latent latch
quaint rock
#

would not add complexity in service of making it dry

chilly surge
quaint rock
#

the guard statements are already a huge upgrade from how most new people with do it with nested ifs

rain minnow
#

True, I wouldn't call the method if it was null . . .

latent latch
#

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

vagrant blade
#

!ban 596888328050180106 bot

tawny elkBOT
#

dynoSuccess minesniffer was banned.

tall salmon
#

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

vagrant blade
chilly surge
rain minnow
chilly surge
#

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.

tall salmon
#

its in spanish

#

here is the full version tho

rain minnow
#

Try and use Google and post the translation . . .

tall salmon
#

it says something by the lines of: you cant modify the given value of " spriterenderer.color" because its not a variable

rain minnow
#

Kinda hard without knowing what the error is saying . . .

rain minnow
dense estuary
#

whoops

#

sorry

#

message wasnt ready yet

dense estuary
rain minnow
# tall salmon here is the full version tho

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 . . .

tall salmon
#

lemme procces it kewk

quartz folio
tall salmon
#

the local variable can be a float right?

#

oh

#

i think i got it

rain minnow
#

Vertx has a page just for this . . .

#

Ahh, there it is!

tall salmon
#

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

dense estuary
#

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?

tall salmon
#

yeah its that error

rigid island
#

yes

tall salmon
#

but idk how to change it

rigid island
#

did you see example on the link ?

tall salmon
#

i think i did it good ( which i obviously didnt)

#

yep

#

i went with this example

rigid island
#
Color color = blackScreenSpriteRend.color;
color.a = somevalue;
blackScreenSpriteRend.color = color;```
tall salmon
#

part 1

rigid island
#

wrong

#

you have to copy the whole struct

tall salmon
#

and here is the other thing

tall salmon
rigid island
tall salmon
#

and what is a struct?

rigid island
#

its a value type object

tall salmon
#

and what do you mean with copy the whole struct?

spring creek
# tall salmon and what is a 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

rigid island
#

did you see the example i sent also?

spring creek
tall salmon
rigid island
tall salmon
#

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

rigid island
#

i make a copy of color, change the alpha value and put the copy back

tall salmon
spring creek
#

Color CONTAINS alpha

#

Alpha is what you called "opaque level" btw

tall salmon
#

thats what i mean
the whole struct is Red Green Blue Alpha

#

thats what i meant with rgba

spring creek
rigid island
#

ys but alpha is a read only property you cannot directly assign it

spring creek
#

Selecting rgba doesn't really make sense

#

You just copy the WHOLE thing

tall salmon
#

but i only want to mess with the Alpha because i want to keep it an exact color

#

doesnt that mess with the RGB?

spring creek
rigid island
tall salmon
#

(just asking for reasoning behind it, not questioning your knowledge)

rigid island
#

you're only changing .a

spring creek
#

Because you are copying the WHOLE state. Changing ONLY alpha, then putting it back

spring creek
#

Since only a is touched, only a is changed

tall salmon
#

just a random name right ?

spring creek
rigid island
tall salmon
#

okey

rigid island
#

you can use whatever u want

tall salmon
#

lemme procces

#

so in my code it would be something like
public color BlackScreenSpriteRend.color

rigid island
#

not at all no

tall salmon
#

dayum

spring creek
#

That is simply not how a variable is created

rigid island
#

this is meant to be a local variable

#

so its disposed once you did what you needed (assign it to color)

spring creek
#

[Accessor] [Type] [Name you make up]

tall salmon
#

oh true

#

YEYE

rigid island
#

there is no need to store it

#

its just a temporary thing to make modifications

tall salmon
#

so i can just make/write/create it inside the function?

rigid island
#

yes

tall salmon
#

okay

#

so color is

#

color color

rigid island
#

no, hover over the color it tells you the type

tall salmon
#

and then you set color to blackScreenRend.color

#

no?

rigid island
#

as I did you can use var when you don't know the type

#

color is not a valid type

tall salmon
#

why not?

rigid island
#

because it doesn't exist?

tall salmon
#

wait im messing things up in my head

#

lemme go back to basics

spring creek
#

Color color

#

That is it. Or var color

rigid island
spring creek
#

No references in a variable declaration (there is qualification, but I don't want to confuse things here)

tall salmon
#

the type of what?

#

variable?

rigid island
#

yes

#

the object you wish to copy/ modify

spring creek
#

Type has a specific meaning. A class name is a type. A struct name is a type. Enum names are types

rigid island
#

and they're all objects, hence OOP

tall salmon
#

what is oop?

rigid island
#

Object Oriented Programming

spring creek
#

Object Oriented Programming

tall salmon
#

damn

#

imma think how i should do it with all this

rigid island
#

you kinda need to learn these things to code in c#

tall salmon
#

with this as a base

tall salmon
rigid island
#

there isn't much to think about

tall salmon
#

but mainly focusing in c#

rigid island
#

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

tall salmon
#

so i could have writed color color

#

and set that color to blackScreenRend.color?

#

and then somehow modify color.a

rigid island
#

color color isn't valid

#

Color color would work

tall salmon
#

color screen could also work?

rigid island
#

Color pepperoni

#

you can name it whatever

tall salmon
#

epic

#

Color color = blackScreenSpriteRend.color;
color.a = somevalue;
blackScreenSpriteRend.color = color;

#

im just reposting so i dont have to scroll

rigid island
#

yes but obv replace somevalue with whatever you need to put there

tall salmon
#

Color Screen = blackScreenSpriteRend.color;

rigid island
#

sure

tall salmon
#

but if i write color.a how does it know to change the color.a of a specific gameobject?

#

thats what i was missing

rigid island
#

it changes the color of blackScreenSpriteRend

#

thats your reference

tall salmon
#

how to tell the exact game object that i want to change color.a

rigid island
#

you cannot use color outside the method if its a local variable

#

just make a copy each time you want to change it

tall salmon
#

is it better to create it as a local variable or as one outside?

tall salmon
rigid island
#

.color

#

you need to copy to modify any of its properties rgba

#

then put it back

tall salmon
#

or why

#

srry if im getting on your nerves im kinda slow

rigid island
#

nah no worries

tall salmon
#

and i also need to traduce everything in my head to a different language

#

so its set up to confusion

rigid island
#

because its a struct you only deal with copies, and alpha is a property of that struct that is read only

tall salmon
#

im thinking

#

what does "read only " mean

rigid island
#

it can only be read?

tall salmon
#

i understand ( i think) that color is a struct and it has property´s inside as Alpha

#

ohhh

rigid island
#

yes

tall salmon
#

so how can i change it if i cant

#

wow that was a strange question to make

#

XD

rigid island
#

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

tall salmon
#

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

rigid island
tall salmon
#

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""

rigid island
#

so where is the confusion

tall salmon
#

im trying to procces it

#

wait

#

im explaining my thought procces so maybe it can help you help me

rigid island
#

"this temporary variable called color of type Color will be copy of the current blackScreenSprite color"

tall salmon
#

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

rigid island
#

oh, that would give you an error as it wouldn't know what color is

tall salmon
#

Color otherWordThatIsntColor = blackScreenSpriteRend.color;
otherWordThatIsntColor.a = somevalue;
blackScreenSpriteRend.color = color;

tall salmon
#

kewk

#

omg it was so simple

rigid island
#

yes lol

tall salmon
#

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

rigid island
#

if you modified it and not assigned it back it would just be modifying a copy

tall salmon
#

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

rigid island
#

yes p is just a copy, you modify it then put it into it as new value

tall salmon
#

im so happy

#

ty my man

rigid island
#

np 🙂

tall salmon
#

i remember you also helped me yesterday

#

kewk

rigid island
#

sweet!

tall salmon
#

or the day before yesterday

#

idk

#

one of em

rigid island
#

haha true I'm around when I can

#

i forget many things tho 😛

tall salmon
#

do you remember something about particles and dont knowing how to call them?

#

that was me in case you remember

rigid island
#

oh I think I suggested Emit(). ?

tall salmon
#

yes

#

i then got another problem wich i already anticipated

rigid island
#

did emit work though i never seen the follow up

tall salmon
#

because right after emit(). there was a destroy(GameObject);

rigid island
tall salmon