#archived-code-general

1 messages · Page 249 of 1

astral relic
#

you mean my system.numerics code is likely backwards ?

quartz folio
#

Yes

astral relic
#

i actually tried that. but its so bad like that, because the translation would be affected by the scale.

astral relic
quartz folio
#

Well, the translation shouldn't be affected by the rotation

astral relic
#

yes.

#

im not sure. maybe unity does it in a different way or sth ?

#

i actually tried all the possible combinations. none acted right.

            //_localMatrix = translationMatrix * scaleMatrix * rotationMatrix;
            //_localMatrix = translationMatrix * rotationMatrix * scaleMatrix;
            //_localMatrix = scaleMatrix * translationMatrix * rotationMatrix;
            //_localMatrix = scaleMatrix * rotationMatrix * translationMatrix;
            //_localMatrix = rotationMatrix * translationMatrix * scaleMatrix;
            //_localMatrix = rotationMatrix * scaleMatrix * translationMatrix;
fervent furnace
#

you are right, should be (T*R*S)*P

quartz folio
#

Yeah, should be. The problem is in that code though, Unity does what makes sense

#

Actually pretty sure it should be T * (R * S)

#

mul(translationTransform, mul(rotationTransform, scaleTransform)).

astral relic
#

let me think and see

nimble cairn
#
    bool CanShootCheck() {
        bool check = Physics.Raycast(camera.ViewportPointToRay(new(0.5f, 0.5f, 0)), out RaycastHit hit, 2.5f, groundMask);

        if (hit.transform && hit.transform.CompareTag("Sphere")) {

            if (hit.transform.GetComponent<Rigidbody>()) return check;
            else return !check;
        
        } else return !check;
    }

Do you guys think you could help me optimize this function?

quartz folio
#

Is there a performance issue with it...?

nimble cairn
#

No, it just feels a little sloppy

#

I'd like to see what I maybe could of done different 🙂

astral relic
quartz folio
fervent furnace
#

if the hit.transfrom not null then check must be true?

gray mural
latent latch
astral relic
nimble cairn
#

@gray mural How so? Are you referring to if (hit.transform)?

nimble cairn
#

@latent latch Could you please provide an example?

nimble cairn
latent latch
#

you return !check twice but you only need to do that once

gray mural
nimble cairn
#

@latent latch I have to do that because not all paths return

quartz folio
somber nacelle
gray mural
somber nacelle
nimble cairn
fervent furnace
#
if(check){
  return hit.transform && hit.transform.CompareTag("Sphere")&&hit.transform.GetComponent<Rigidbody>();
}else{
  return true;
}
gray mural
fervent furnace
#

branchings are still here

#

just utilize short circuit

nimble cairn
#

@fervent furnace Let's try this out!

fervent furnace
#

oh, i am wrong

nimble cairn
#

😮

fervent furnace
#

let me think about it
if hit.transform !=null then check is true, that means if transform.comparetage is falas it returns !true=false
if they are true then return true if there is rigidbody, !true if no

#

so transform&&tag&&rb should be correct, if trsnsform is null that means check is false, return !false=true

quartz folio
#

Checking hit.transform is redundant if you've checked check

#

If it hit something, it has a transform

fervent furnace
#

you are right, remove the hit.transform

nimble cairn
#

I am pretty lost here guys

#

Wait

fervent furnace
#
return !check||hit.transform.CompareTag("Sphere")&&hit.rigidbody;
```one line
quartz folio
#

Also didn't hit have a rigid body field?

fervent furnace
#

yes

nimble cairn
#

Thanks!

#

Awesome, this is great!

swift falcon
#

Hello! Im trying to set a variable of an instantiated gameObject, but unfortunately I keep getting this error. Can anyone help me a little?

knotty sun
#

It might help if you included lines numbers. also !code

tawny elkBOT
fervent furnace
#

not code general
is line 22 answer.text=text?

swift falcon
knotty sun
#

so answer is null

fervent furnace
#

have you set it in inspector?

swift falcon
#

i thought so

swift falcon
knotty sun
#

that sets a local varaible

fervent furnace
#

dont just think, check it
second script is irrelevant

swift falcon
#

should I make it public?

knotty sun
#

how do you declare answer in the first script

swift falcon
knotty sun
#

so how do you expect it to contain a value?

fervent furnace
#

so did you make the variable reference an actual TMP_Text object (component)?

swift falcon
fervent furnace
#

is the text on the prefab or some gameobject on world eg canvas

swift falcon
#

an I like used a canvas on the prefab in order to add the text is that okay?!

knotty sun
#

you might be better using dependency injection.
Can the second script which does the Instantaite get a reference to the first script?

fervent furnace
#

he says the text on the prefab so he can just drag the component and drop it to the field

knotty sun
#

but he want a reference to the instantiated object not the prefab

swift falcon
#

how can I have a text without a canvas, or is that evenm possible?

knotty sun
#

@swift falcon Dependency Injection
...
Script1 needs a reference to answer

Script2 instantiates answer
Gets a reference to Script1
script1.answer = answer
knotty sun
swift falcon
knotty sun
swift falcon
#

tyy

#

but im using 2d object

#

im making a 2d game

knotty sun
#

should still work

swift falcon
#

alright

#

ty

swift falcon
delicate rampart
#

No active UnityEngine.XR.ARSubsystems.XRCameraSubsystem is available.

Anyone knows how to correct this error?

knotty sun
swift falcon
#

its an issue with the txt string

#

since I looked at an instantiated object, it had the answer value set

knotty sun
#

so the null ref has now gone?

swift falcon
#

nope

#

imma send all code

knotty sun
#

then it has nothing to do with the text string

#

show the inspector of the script

#

this is not a code problem, it is a setup problem

swift falcon
swift falcon
#

in the second script from above, its value is set

knotty sun
#

and answer has not been set

swift falcon
knotty sun
#

you need to set variables here

swift falcon
#

they are set at the beginning of start()

knotty sun
#

which is obviously not working, set answer in the inspector and not in code

swift falcon
#

why not in code?

fervent furnace
#

you get NRE => your code not work

knotty sun
#

obviously something wrong with your logic of where the component is

fervent furnace
#

run doesnt mean work

knotty sun
#

btw hardcoding like that is very bad practice and often prone to break as you have found

delicate flicker
#

I have a problem. I throw Raycasthit2D.hit.point at some part of the gameobject (a platform for example) and apply it to Springjoint2D.connectedAnchor. This is how i implement a grappling hook. But problem is, when this platform is moving, my player stays on the same position and i need to move it with the platform. Transform.position of this platform is not a solution, because it is the position exactly on the center of the platform, whereas i was attached on the corner of the platform, for example. How can i update connectedAnchor accordingly with the movement of the platform?

trim rivet
#

anyone know how to edit post process volume settings at runtime?

#

can't seem to find good info on this online

cold egret
#

- How can i change the float value type to int? I'm not looking for casting, that'd mess up the bits order within the float. I need to preserve the bits sequence while changing their type to int

#

- The only solution i can think of rn is a struct with explicit memory layout. Any other solution?

late lion
wise ermine
#

Hey everyone, I have a git question.
I added the first .gitignore file I found on Google but now when I run git status I see the following weird files/directories:

  • ProjectSettings/EditorBuildSettings.asset
  • Adaptive Performance/
  • Adaptive Performance.meta

Are .meta files and the rest of the listed ones necessary to be tracked in git?

rigid island
#

.meta files are very important

narrow nebula
#
    public List<BuffTarget> buffTarget;
    public List<int> buffAmp;```
any way to "combine" variables so I wont have to fiddle with 3 different lists?
fervent furnace
#

impossible if you cant cast one to other or using object everywhere

fervent furnace
rancid jolt
#

The animation is running but after completion it is not coming back to the idle state. The normalizedTime condition looks right?

late lion
fervent furnace
#

you can warp like this but you need additional check

#

unless he want to group the value together

wise ermine
late lion
limber raft
#

I'm trying to learn compute shaders, but I can't figure out how to calculate the range that SV_DispatchThreadID will give. The Microsoft docs give a formula, but trying it in Wolfram Alpha doesn't work. I'm probably using the wrong operations, so does anyone know the right ones?

limber raft
#

SV_DispatchThreadID is the sum of SV_GroupID * numthreads and GroupThreadID

leaden ice
#

Right so it's basically the (x,y,z) from your kernel itself scaled by the xyz you pass into dispatch?

It's been a while since I used compute shaders

cold egret
limber raft
fervent furnace
#

Unity.Collections.LoweLevel.Unsafe.UnsafeUtility, full of pointer stuff

latent latch
#

sounds pretty unsafe

limber raft
# leaden ice Right so it's basically the (x,y,z) from your kernel itself scaled by the xyz yo...

I think I figured out that it's just supposed to be the Hadamard product

In mathematics, the Hadamard product (also known as the element-wise product, entrywise product: ch. 5  or Schur product) is a binary operation that takes in two matrices of the same dimensions and returns a matrix of the multiplied corresponding elements. This operation can be thought as a "naive matrix multiplication" and is different from the...

leaden ice
limber raft
#

oh that makes more sense

leaden ice
hard viper
#

As far as assemblies go, is there a simple way for me to make one asmdef that is then equivalent to what I currently have in my project, which is C#-assembly default assembly?

#

my plan is: 1) make my own giant equivalent C# assembly, 2) slowly break it up into smaller assemblies where each assembly I add keeps everything working properly

leaden ice
hard viper
#

i tried, but DOTween is not happy with this because it has its own .dll

#

i think I’ll give it another shot tho

#

so... all my scripts are in subfolders of Assets. Therefore, if I put an asmdef in Assets directly, everything should still work?

leaden ice
#

Yeah I'd just move all your own scripts into a folder not mixed with any packages or assets

#

DOTween will need an asmdef too though

hard viper
#

step 1 is to make a giant assembly where everything is working. Then slowly split everything up in a way this is non-stupid

leaden ice
#

And you'll need to reference it

stone rock
#

Hello, are there any peformance differences between Physics.Linecast and Physics.Raycast?
If the length is specified they would be practically equal right?

rigid island
stone rock
#

yeah, just wondering if there are differences

bright token
#

Im trying to connect a mysql database to my unity game, so I imported the connector mysql.data.dll file and the system.data.dll file but I get the error message:

stone rock
#

they do the same thing in the end only the parameters are a little different

latent latch
#

what's the difference

rigid island
latent latch
#

seems like linecast just returns a bool?

knotty sun
simple egret
#

I'd say they can be used interchangeably, it depends on what data you have as input.
Raycast takes in a start point, direction, and distance
Linecast takes in a start point and an end point

latent latch
#

so performance probably doesn't matter if you use nonalloc

bright token
latent latch
#

oh, wait there is a overload method with a rayhit

knotty sun
bright token
#

oh that explains it

#

so I search for a connector from version 3.5?

knotty sun
#

yes, if you cant find it, DM me and I'll send you a copy

bright token
#

thank you

#

well which one?

knotty sun
#

which is .Net Framework 3.5

bright token
#

i dont have 4.x or 3.5

hard viper
#

I put an asmdef in the root Assets folder, but now none of my scripts can see anything in Packages, and it doesn't look like unity lets me add an asmdef to it. Is there a way to make the packages a dependency?

#

or do I just need to manually add every single package in my project as a dependency of a given package asmdef or something?

rigid island
leaden ice
hard viper
#

ok. that sucks, but at least I have a plan.

delicate flicker
#

How to get position of some part of the gameobject? transform.position return the center of this gameobject and i can throw raycast to some part that not the center and i need to return this as local position on this gameobject

hard viper
#

you need to have some way to reference it

hard viper
#

like using the bounds of a collider, or a separate child gameobject, or a fixed offset vector saved for that gameobject

#

collider bounds is kind of shit, so I will frequently go by the dimensions and offset of the collider

#

eg: transform.position + boxCollider.offset + boxCollider.size….

#

or whatever

delicate flicker
#

@rigid island for example, i throw raycast that hit this gameobject (a platform object, to be precise), return .point as Vector2. I hit closely to the corner of this platform. I send this to Springjoint2D.connectedAnchor. This is how a grappling hook works. BUT when the platform moves, my player stays on that point which i hit previously on the world space and not with the platform.

hard viper
#

it sounds like you need a conversion between local and world space

delicate flicker
#

I can bind it to transform.position, so when it moves it updates to it, but is it the center of this platform, and i need to update position exactly on that part i hit on the platform

hard viper
#

ok there’s a lot to unpack here

#

if you have a springjoint2D, then it should be linked to a rigidbody

rigid island
hard viper
#

it sounds like you just want the springjoint2D to be offset to target a specific point relative to rigidbody position

delicate flicker
#

Recently the mechanic doesn't rely on the rigidbody and connectedBody property. I need to update connectedAnchor

hard viper
#

the platform has a kinematic rigidbody2D?

#

and player is dynamic rb2D?

delicate flicker
#

@rigid island i can't figure out the calculation how to do it

#

That's why i ask

delicate flicker
#

And has velocity update

hard viper
#

is connectedanchorpoint in local space or world space? I’m not too familiar since i’ve had to scrap joints before

#

if you need to recompute the point every frame, you just need to use a transform method to convert

hard viper
#

that is bizarre, since I feel like that defeats the purpose of a joint2d

#

but either way:
platformTransform.InverseTransformPoint(pointYouHitInWorldSpace) gives you the local space point of where you hit. and you would save this as the grappling hook’s offset

delicate flicker
#

I tried this method

#

It launches my player into cosmos

hard viper
#

platformTransform.TransformPoint(localPoint) gives the world pos

hard viper
delicate flicker
#

It is, raycasthit2d.point returns exactly this

hard viper
#

the whole point of a Joint2D is to apply constraints that affect DURING physics simulation. It would be nonsensical if you had to specify the joint to target a spot in worldspace

hard viper
#

raycast will always give world space, because physics queries always exist in world space

#

the joint should only care about relative space

delicate flicker
#

Ok i see now, connectedAnchor is local

hard viper
#

Joint2D don’t have business dealing in world space

#

i just didn’t know how the field output it

#

either way, you need to take your hit position (world pos of grappling hook), and convert to local space of platform with platformTransform.InverseTransformPoint

#

this gives the point in local space of grappling hook, which is also the offset for the spot we need to connect

delicate flicker
#

I checked, it says that connectedanchor is world pos when no rigidbody connected

#

And my springjoint doesnt connect to rigidbody

hard viper
#

that makes no sense

delicate flicker
#

I get confusion

hard viper
#

because you said it breaks when your platform moves

#

but why are you moving your platform if it lacks a rigidbody

delicate flicker
#

Yes, but it doesn't apply as connectedBody

hard viper
#

i don’t see what the problem is

#

if you move the platform, it needs a rigidbody.

#

if you want to joint your dynamic rb to a kinematic rb, the joint needs to know both RBs as targets

#

then when both move during physics sim, simulate will apply a constraint between the two RBs to apply force between them, as it tries to satisfy all the conditions of your system (eg position, velocity, time, force, mass, collisions….)z

#

does this make sense?

tacit swan
#

is there something equivalent to quaternion.identity for a 90 degree rotation or 180 degree rotation?

hard viper
tacit swan
#

oh yea

hard viper
#

either way, I think there is Quaternion.Euler

tacit swan
#

im just using Quaternion.Euler(0,0,90) rn

heady iris
#

Quaternion.identity is a zero-degree rotation

#

so yeah, just use Quaternion.Euler

tacit swan
#

ah

heady iris
#

You could make a static class with some preset values, I guess

hard viper
#

quaternions can multiply btw

tacit swan
#

also does Vector2.down depend on the rotation of the gameobject or does it always just point down relative to the world space?

heady iris
#

Vector2.down is [0, -1], always

#

how you interpret this vector is important

hard viper
#

transform.rotation *= Quaternion.Euler(0,0,90f);

tacit swan
#

ah is there a way to get the direction that the gameobject is facing?

hard viper
#

transform.up, transform.left…

heady iris
#
transform.TransformDirection(Vector3.down)
-transform.up

These are equivalent.

tacit swan
delicate flicker
# hard viper does this make sense?

Absolutely makes. But as i said, my mechanics of the grappling hook only relies on connectedAnchor, i doesn't apply to connectedBody, i never connect to any rigidbody EVEN though these platforms have rigidbody and moves. Because i attach my hook to raycasthit2D.point which is world position. I don't want to rewrite this mechanic, and that's why i ask how to update position to connectedAnchor relatively to the moving platform

heady iris
#

annoyingly, there is no transform.left or .down or .back

tacit swan
#

rip

tacit swan
#

like do transform.up and then rotate based on what u want?

hard viper
#

if (attaching to moving platform) set rigidbody and calculate local position;
else connect to world pos

#

you do not want to connect two rigidbodies together, by shittily just tracking behind some position.

delicate flicker
#

Ok, i'll try

heady iris
tacit swan
#

for example if i wanted to get transform.right

heady iris
#

if you want to get the direction you're facing, just do transform.right or transform.forward or whatever is the "facing direction"

hard viper
#

i can guarantee that what you were asking for (recalculating world pos every frame without jointing the RBs) will lead to jank

tacit swan
#

sorry i misunderstood

raven basalt
#

I have a ramp that uses the Floor physics materrial. No matter what I adjust the static friction to, the player either slides off the ramp if the static friction is too high, or the player starts moving backward when I try to make it go forward if the static friction is too low.

heady iris
#

if the dynamic friction is zero, that means that moving objects will be frictionless

#

note how you've set Friction Combine to "Minimum"

#

so no matter what the friction is on the other object, you're getting 0 dynamic friction at all

#

(assuming that one's physic material is set to Average)

raven basalt
#

But if the dynamic friciton is anything greater than 0, when I try to make the player go forward, the player instead goes backward because of the friction

hard viper
#

unity friction is ass. i basically always set it to zero

#

but this also means having to set gravity to zero on slopes/grounded

crystal creek
#

does anyone know what causes all the materials in my asset bundle to be loaded invisible while using universal render pipeline? and is there a way i can load it or build it differently possibly to not have this issue?

raven basalt
crystal creek
#

why does your floor have a rigidbody if its static?

raven basalt
#

Tbh I forgot the original reason as to why I put it there. Should I remove it?

crystal creek
#

yeah

#

you only need the physics material

#

and that is set on the collider

raven basalt
#

Do these values look good for the physics material?

crystal creek
#

depends, what for

#

your player to collide with?

raven basalt
#

I want to apply it for a ramp that the player can walk on. No matter what I adjust the static friction to, the player either slides off the ramp if the static friction is too high, or the player starts moving backward when I try to make it go forward if the static friction is too low.

#

And same goes for the dynamic friction

crystal creek
#

it might be better to apply the physics material to the player itself then

#

and keep all other ones as is

#

you can adjust/swap out the physics materials based on the players moving state too then

raven basalt
#

I currently have a player physics material applied to the player

crystal creek
#

just use that, reset the other one

#

and set the friction on both settings for the player to 0

raven basalt
#

But now the player slides off the ramp

crystal creek
raven basalt
#

so the player's physics material is going to change depending on if it is moving or not?

raven basalt
#

Should I do it based on input, like if the player is currently holding down the key that causes the player to move, the player's phyiscs material switches, or should I detect if the player's rigidbody is currently moving, and then switch physics materials based on that?

onyx oriole
hard viper
#

very different

onyx oriole
#

I have a controller for the cube to rotate for example 90 degrees right if im moving right , 90 degrees forward if im moving forward, and an animation separately to give it a jump animation but it doesnt seem to work

#

it just goes lower and lower into the platform

latent latch
#

should just post the code

onyx oriole
#
{
    isMoving = true;

    playerAnimator.speed = 1*(1 / moveDuration); // Synchronizes the speed of the animation to match the speed at wich the player moves
    playerAnimator.SetTrigger("Jump"); // Adds the jump animation (y from 0 to 1 and back to 0)

    Vector3 initial_pos = player.position;
    Vector3 target_pos = player.position + direction;

    Quaternion initial_rot = Quaternion.Euler(player.eulerAngles);
    Quaternion target_rot = Quaternion.Euler(new Vector3(direction.z*90, 0, -direction.x*90));

    float duration = moveDuration;
    float elapsed_time = 0f;

    while(elapsed_time < duration)
    {
        player.position = Vector3.Lerp(initial_pos, target_pos, elapsed_time / duration);
        player.rotation = Quaternion.Lerp(initial_rot, target_rot, elapsed_time / duration);

        elapsed_time += Time.deltaTime;

        yield return null;
    }
    player.position = target_pos;
    player.rotation = Quaternion.Euler(Vector3.zero);

    isMoving = false;

}```
round violet
#

is there a way to debug and "see"/know what is modifying my player position
i checked all scripts, rigidbodies and colliders, and my player is moving down in a moment were it shouldn't, i cant find what is "making it going down"

latent latch
# onyx oriole

without any of the rotation, it seems like your animation keyframe starts in the middle and ends lower than the first

onyx oriole
#

starts at 0

#

ends at y 0

#

in the middle its y:1

#

i removed rotation it still goes down

#

let me see if i just do the animation no movement

#

Oh i think i found it

latent latch
#

if you look at the blend tree it starts at the middle

#

but the next iterations start at the beginning

#

(also the fact it never completes a full animation cycle) oh, Im looking at the wrong block, half asleep here

onyx oriole
#

in the transition or where do i check

onyx oriole
latent latch
#

yeah im not too sure, but the animation is from 0 to 1, but your first iteration goes for 0.8 to -0.2

#

what makes it confusing is you're doing some positional logic in the animator but some in code

#

so perhaps there's some confliction on the timing/positional values between the two

#

what I'd do is trigger the jump, await the clip, then proceed with the rotation and movement to the next spot

#

or perhaps just make them both animation clips

kindred cairn
#

Hey guys, how are you? Can anyone help me with a question, or advise me on my project: I'm creating an EnemyIA that will use A* pathfinding to find the target, so far so good. My problem is how can I do it for large maps, as it would take a long time to return the calculation and this could cause slowness. The idea I had was to create several grids, each representing a region of the map, so I wanted to find a tutorial that could shed some light on this and also here on the discord channel.

fervent furnace
#

it is called hierarchical search
almost all methods for reducing run time of graph algorithm is to reduce number of vertices and edge

kindred cairn
#

Hierarchical search, does it have another name? Because I'll try to find out on YouTube or Google.

heady iris
#

It sounds familiar to me, but I'm not sure what to call it

#

It's almost like LODs for your navmesh

#

one big low-fidelity graph for long-range calculations

kindred cairn
#

I found it, but it's not about create a map and divide it in grids, i'm looking for the name of this process

heady iris
#

and then another high-fidelity graph for navigating up close

rotund niche
#

https://www.youtube.com/watch?v=hKGzSYXPQwY&t=84s&ab_channel=SasquatchBStudios im using this video to learn to use unity at 2:08 is a script and when i copy it in unity it says its wrong why

Unity Asset Store BLACK FRIDAY Sale - EVERYTHING on this page is 70% off:
https://assetstore.unity.com/?flashdeals=true&aid=1100lwgBQ

Join our Discord Community! - https://discord.com/invite/aHjTSBz3jH
Show your Support & Get Exclusive Benefits on Patreon (Including Access to this project's Source Files + Code) - https://www.patreon.com/sasquat...

▶ Play video
heady iris
#

that is extremely vague

rotund niche
#

whats the diffrence???

heady iris
#

the second screenshot has quite a bit of code that isn't in the first one..

rotund niche
#

thats missing

heady iris
heady iris
rotund niche
#

yes

#

hows it not the same?

#

i forgot to screenshot full code

kindred cairn
rotund niche
#

@heady iris look at both my codes whats wrong with them?

#

i used chatgpt and it said the code has nothing wrong with it

heady iris
# rotund niche

you changed your script in between sending this image and the new image. line 28 now looks okay

#

however, it also looks like !ide is not configured. please follow the instructions in the bot message below:

tawny elkBOT
rotund niche
heady iris
#

actually...i'm bad with colors

rotund niche
#

damm

#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;

public class FlyBehavior : MonoBehaviour
{
[SerializeField] private float _velocity = 1.5f;
[SerializeField] private float _rotationSpeed = 10f;

private Rigidbody2D _rb;

private void Start()
{
    _rb = GetComponent<Rigidbody2D>();
}

private void Update()
{
    if (Mouse.current.leftButton.wasPressedThisFrame)
    {
        _rb.velocity = Vector2.up * _velocity;
    }
}

private void FixedUpdate()
{
     transform.rotation = Quaternion.Euler(0, 0, _rb.velocity.y * _rotationSpeed);
}

}

#

this the code

heady iris
#

Which of these is your code? I don't know which one is yours and which one is from the tutorial.

#

i think that answers my question, haha

rotund niche
#

ill resend screenshots

#

with showing video code

#

this mine

heady iris
# rotund niche

Your code editor is not configured properly. You should be getting auto-complete when typing, and errors should be highlighted with red squiggles.

rotund niche
#

this his

rotund niche
heady iris
#

my IDE is on the right. notice how i've got colors

heady iris
spring creek
tawny elkBOT
spring creek
#

Oh damn. You're checking the IDE

Sorry, screenshots make sense in that case

rotund niche
#

should i just install visual studio community?

heady iris
#

First, go back and make sure you've followed every step

rotund niche
#

99% since i did it twice

heady iris
#

Go back and check each step.

#

Make it 100%.

#

Then close VSCode and click this in the External Tools settings screen

#

If it still isn't working, show me screenshots of your package manager and of the External Tools settings

rotund niche
#

alr

heady iris
#

If you don't know where that settings screen is, I don't think you followed all of the instructions.

rotund niche
#

in the video

heady iris
#

This has absolutely nothing to do with the video

rotund niche
#

oh

heady iris
rotund niche
#

@heady iris

#

what does that mean

#

@heady iris

#

why has this happened now

#

(i fixed the code)

normal fulcrum
#

Hi folks - is there a way to retroactively apply a root namespace after applying it in project settings in unity? Can't seem to find an answer to this one on other postings. I have all my scripts in my Script folder and subfolders, but is there a way to add that root namespace en mass?

faint brook
#

I recently added this code into my project: ```c#
public void Login()
{
Debug.Log("here");
IList<object> names = GetColumnValues(sheetsService, spreadsheetId, "Sheet1", "A");
int row = names.IndexOf(usernameInput.text);
string correctPassword = GetCellValue(sheetsService, spreadsheetId, $"B{row}");
passwordEncrypted = GetHashString(Password.text);
Debug.Log(correctPassword);
}

leaden ice
faint brook
#

I was looking at the event system and realized when I was clicking on the login button I was actually interacting with a ui elament that behind it. But now I am confused becuase it belongs to a diffrent canvas group that is disabled (alpha = 0 and is not interactable)

tranquil canopy
eternal dome
#

why when i call the method nothing happens i want to change the weight of this but nothing happens

leaden ice
leaden ice
#

structs are not references, they are value types

simple egret
#

Wonder why it isn't erroring like it would when doing transform.position.x = 42

#

Is data not a property?

leaden ice
#

not sure

#

I mean maybe it is erroring

#

and their IDE is not configured

eternal dome
#

not for me?

leaden ice
#

not for you what? Those messages are definitely for you

simple egret
#

Maybe it's like the particle system module shenanigans lol, where it magically references the original data

soft shard
# tranquil canopy does someone knows how could i resize the right boxhelp in realtime with the lef...

You could give it a GUILayout.Height and store the value as a variable so you can use it on both, or put both in a EditorGUILayout.HorizontalGroup and set both the left and right to GUILayout.ExpandHeight(true), then they should match whatever height you set the horizontal group to - there is also a #↕️┃editor-extensions channel you can try for more suggestions - and as a small sidenote, you can use scopes instead of "begin/end" for layouts, such as

using (new GUILayout.VerticalScope(...))
{

}

Where the "..." would be where you can define GUILayout stuff and optionally an EditorStyle, its a bit more organized, and in VS you can collapse these scopes, I believe it may also have some performance gain if that becomes a concern for you, since you can cache them as well

tranquil canopy
raven basalt
#

My player is able to walk on flat surfaces, but it is unable to walk up sloped surfaces. How do i fix this?

    private void FixedUpdate()
    {

        if (inputMovement == 0)
        {
            // Set the gameObject's Collider physics material to stationaryPlayer
            collider.material= stationaryPlayer;
        }
        else
        {
            // Set the gameObject's Collider physics material to movingPlayer
            collider.material = movingPlayer;
        }

        // Movement
        rbody.velocity = new Vector3(inputMovement * walkSpeed, rbody.velocity.y, 0);
        ............


    }
leaden ice
#

that's going to make it difficult

normal quest
#

this tutorial helped me a lot to deal with slopes, maybe you will have to adjust some stuff from your player controller but it is worth to watch it
https://www.youtube.com/watch?v=QPiZSTEuZnw

raven basalt
normal quest
#

it can work for 3D but you will have to listen carefully to the youtuber explaining why things don't work and how he fixes them, there's nothing you can't do with a little thinking

shell scarab
#

even when I have a lot more in the room.

soft shard
leaden ice
shell scarab
leaden ice
shell scarab
#

well I'm pretty sure that's the method to delete actual rows and columns

leaden ice
#

maybe share your code?

shell scarab
#
public class Starter : MonoBehaviour
{
  public Room room;

  void Start()
  {
    room.Tilemap.DeleteCells(new Vector3Int(1,1), 1, 1, 1);
  }
}

public class Room : MonoBehaviour
{
  [SerializeField] private Tilemap m_tilemap;
  public Tilemap Tilemap => m_tilemap;
}
dense rock
#

Hey, in my Option class I want to have a list of conditions. Each condition has one ScriptableObject which it compares to another SO (these SOs each only have a value). Each SO is either IntValue, BoolValue, etc.
Currently they don't inherit from a base class and neither do they implement an interface. Same goes for the conditions, IntCondition, BoolCondition, etc.
Now it makes my life hard, having to implement a list for each type of Condition/SO I have.
Condition classes should have a public bool method, which says if the condition is met. I only need multiple classes for each datatype, because they have different comparison operators... I would like to have conditions implement an interface, but then how would I be able to edit the List<ICondition> in the inspector? Is there an easier method than to just add tons of lists for each condition type?

#
public class DialogueOption
{
    // want to have all of them in one list
    // for expandability and structural reasons
    public List<IntCondition> intConditions;
    public List<BoolCondition> boolConditions;
}
public class IntCondition : ICondition
{
    public GlobalIntValue firstValue; // GlobalIntValue is an SO
    public IntComparison op; // enum to choose from (<, >, ==, >=, etc.)
                             // this enum is what seperates conditions
    public GlobalIntValue compareVariable;

    public bool ConditionIsMet()
    {
        switch(op) { ... }
    }
}
public class BoolCondition : ICondition
{
    public GlobalBoolValue firstValue; // GlobalBoolValue is also an SO
    public GlobalBoolValue compareVariable;

    public bool ConditionIsMet()
    {
        return firstValue.Value == compareVariable.Value;
    }
}
quartz folio
lost mirage
#

Reposting here because I haven't really gotten a good answer or explanation in #📲┃ui-ux

I'm trying to recreate Yugioh Master Duel's deck builder UI. But I'm having trouble on the best way to implement it.

To me, it looks like most of it should be done using Unity's UI System. However, my cards are World Space Game Objects.

I want to programmatically create Game Objects of cards and display them in the UI container on the right, similar to Yugioh Master Duel's UI

In the screen shot, the White Boxes are UI Images, which work as expected. If I add enough White Boxes, the container will begin to scroll

However, the Red Circles are World Space Game Objects. They do not affect the UI Container at all. If I keep adding Red Circles, the UI Container will not scroll.

latent latch
#

What are 2D game objects? You want to use rectTransforms with images

lost mirage
#

They're world space game objects

#

As if you created them from 2D Object -> Sprites -> Circle

latent latch
#

But don't you still use rectTransforms on a world canvas, I'm not understanding

#

Or are you using a normal canvas but somehow childing actual transforms onto it

#

in that case you shouldnt and instead be using UI Images and taking a references from those world objects

lost mirage
#

There's a scroll view. The White Squares are UI Images, so when I add them, they automatically get displaced by the 10 px padding. If I keep adding them, the scroll bar will be able to scroll. But the Red Circles are World Space Game Objects, so they don't affect the scroll view at all and just appear on top

lost mirage
#

Here's what my prefab looks like btw

latent latch
#

Sprite components shouldnt be on the UI. Sprite is Unity's way of batching 2D objects in the scene, but if you're using UI then you should be using UI components like Images

lost mirage
#

Yeah so that's where I'm confused

#

When you're actually playing the game, it's going to be using regular 2D objects in world space. Not UI

#

But in the Deck Builder, it clearly looks like UI to me

#

And if I want it to be responsive, then I think I should use UI

latent latch
#

Then you have both, UI Images and 2D sprites but reference the same "Imported Image" for both components

lost mirage
#

But my card prefab is not UI, so I guess I need to mix and match them somehow?

quartz folio
#

Make two versions

#

Or have a fun time and calculate the world space positions and scales from UI objects and place the 3D versions there as if they were in the UI. Get the update order with UGUI layout correct (a nightmare), and avoid all cases where sorting with the UI is a thing

lost mirage
#

So I should create a replica of my MonsterCard prefab using UI components?

quartz folio
#

That is what I have done in the past

latent latch
#

Is Yugioh's card game made in Unity? I know Hearthstone is if you've not checked that out.

lost mirage
#

Not sure what Yugioh is made in. Hearthstone is made in Unity, but their deck builder has a completely different design

quartz folio
#

Hearthstone also avoided UGUI iirc, just did it using meshes

latent latch
#

Yeah, I know the game field is meshes, but I thought the deck builder was UGUI

#

but ive not played it for a while

frail nest
#

Not sure if this is the right channel, but it does have something to do with programming.
If I merge two branches locally, and other person merged the same branches locally, will it cause conflict when the merged branches get merged in the future?

leaden ice
vital oracle
#

How would you go about creating a grid and then having data associated with each grid location, i.e. (0, 0), (12, 15)?

In the past I've used a two dimensional array, but always have trouble with how to then associate the appropriate data for each array position. How would you store this data? Say for example you want each tile location to have a tile type associated with it. Land, ocean, etc.

fervent furnace
#

2d array or flatten 1d array
and what is the problem of associate the data to index?

#

fancy way is to use quadtree

nimble cairn
#
// Change pitch based on camera angle
float currentCameraAngle = camera.transform.rotation.x;

audioSource[0].clip = audioClips[0];
audioSource[0].volume = 0.75f;

if (audioSource[0].pitch > 2.5f) audioSource[0].pitch = 0.3f;
if (audioSource[0].pitch < 0.3f) audioSource[0].pitch = Random.Range(0.3f, 0.75f);
if (previousCameraAngle < currentCameraAngle) audioSource[0].pitch -= 0.065f;
if (previousCameraAngle >= currentCameraAngle) audioSource[0].pitch += 0.065f;
            
audioSource[0].Play();

previousCameraAngle = currentCameraAngle;

Hi again folks, just wondering if anyone could help me optimize this absolute spaghetti code. I've tried a method with Mathf.Clamp but I can't seem to get it right.

It works perfectly, but every time I look at this section I get the heebie-jeebies.

leaden ice
#

Have you actually tried debug.logging that?

#

It's not what you think it is

nimble cairn
#

I only want to change the pitch whilst the camera goes up/down

#

That's not the part that I'm really worried about tbh.

leaden ice
#

It's fundamental to the whole thing

nimble cairn
#
if (audioSource[0].pitch > 2.5f) audioSource[0].pitch = 0.3f;
if (audioSource[0].pitch < 0.3f) audioSource[0].pitch = Random.Range(0.3f, 0.75f);
if (previousCameraAngle < currentCameraAngle) audioSource[0].pitch -= 0.065f;
if (previousCameraAngle >= currentCameraAngle) audioSource[0].pitch += 0.065f;

This is literally the only part I have a problem with.

leaden ice
#

Believe me you have a problem with the rotation.x part too

#

Anyway it's really unclear what you want the relationship between the camera pitch and the sound pitch to be

#

But rotation.x is NOT any kind of angle around anything at all.

#

It is what?

nimble cairn
#

It's a clamped value between -90f and 90f

leaden ice
#

It's a quaternion component

#

And will only give you a value between -1 and 1, and it doesn't represent an angle at all

#

Debug.Log it, you'll see

nimble cairn
#

No, it gives me a value between -90f and 90f

leaden ice
#

Prove it, I don't believe you

nimble cairn
#

I don't need to --- I just want help fixing those four if statements.

Just change camera angle to foo and bar if it helps.

#

The camera angle is not an issue here 😆

leaden ice
nimble cairn
#
if (audioSource[0].pitch > 2.5f) audioSource[0].pitch = 0.3f;
if (audioSource[0].pitch < 0.3f) audioSource[0].pitch = Random.Range(0.3f, 0.75f);
if (foo < bar) audioSource[0].pitch -= 0.065f;
if (foo >= bar) audioSource[0].pitch += 0.065f;

This is literally the only part I have a problem with.

leaden ice
#

You'd have to explain what you want the relationship to be

#

foo and bar aren't making this anymore clear

nimble cairn
#

Okay as the camera looks up/down, the pitch of my gun SFX goes up and down with the movement.

leaden ice
#

But with what relationship?

nimble cairn
#

And has a reset value at a max of 2.5f, and a min of 0.3f

leaden ice
#

From that description just sounds like a basic remapping function

nimble cairn
#

No -- that's not what I'm looking for sadly.

leaden ice
#

Well you haven't explained clearly what you are looking for

fervent furnace
#

do you know what are else and ternary operator? google them

lost mirage
#

If you just want the pitch to change at a constant rate with the camera movement, why can't it be a simple mathematical formula?

fervent furnace
#

btw idk why it minus/plus a constant no matter how the delta angle is

lost mirage
#

There's some other weirdness going on in there

nimble cairn
nimble cairn
fervent furnace
#

i mean delta angle, not the sign

#

btw if it works then fine

nimble cairn
#

It works perfectly fine 🙂 I was only hoping to see how I could of maybe achieved this result differently.

lost mirage
#

Could be something like this

function (var currentCameraAngle)
{
    const absMaxCameraAngle = 100;
    const absMaxPitch = .9;

    var percentage = currentCameraAngle / absMaxCameraAngle;
    return absMaxPitch * percentage; // new pitch
}
nimble cairn
#

Yeah cool! Camera to %

#

Thanks! @lost mirage

dense tusk
#

all my fellas, i require assistance. i'm using a character controller component to for my player object, and i want the player to increase in speed when the button is pushed to walk, and decrease in speed when the button is released. i've gotten this to work by taking advantage of the input manager and manipulating the settings there, but i'm struggling to get the movement normalized.

here i tried to use a method i'd seen online, it did not work.
https://paste.ofcode.org/NjkBb6ER6qS6MT2heMfxmL

and this does normalize, but it doesn't preserve the acceleration and deceleration when they move. it just becomes an instant stop and start
https://paste.ofcode.org/nWg7jmGGBpq2tp4Xv9d6JE

any insight would be appreciated lads.

leaden ice
#

Normalizing it is completely at odds with anything except full speed at all times

dense tusk
#

because i don't want the speed to increase more than intended when the player moves diagonally. i assumed normalizing was the simplest way to fix that

dense tusk
#

thanks for the info. what does normalizing do that's different?

leaden ice
#

Do you know what normalizing means?

dense tusk
#

apparently not since i was using it in the wrong place

leaden ice
#

A normalized vector is a vector in the same direction but with magnitude of 1. So if it was shorter than 1, or becomes 1 and if it was longer than 1 it becomes 1.

In your case you want to make vectors longer than 1 to be length 1, but you should leave vectors shorter than 1 alone

#

Normalize won't leave those shorter vectors alone, but ClampMagnitude will

dense tusk
#

so normalize just works in 0's and 1's then? it doesn't use anything that falls between them?

leaden ice
dawn nebula
dense tusk
#

oh that is different. now i see. thanks y'all

dawn nebula
#

It forces the vector to land somewhere on the unit circle.

dense tusk
#

damn normalize really just says "fuck your number, you're getting a one"

dawn nebula
#

yes

#

Normalized vectors are very useful when you want to represent just a direction.

vital oracle
#

Any tips on how I can procedurally generate a shape like this. I have a grid array already, but want to have a method generate a shape like this and then assign the values to each position, i.e. water and land. For now to keep it simple, I'm just using an int based grid so 0 = water and 1 = land.

I tried a few methods like creating it line by line with random ranges for the length of each row, but I can't get anything that looks natural.

dawn nebula
#

I've got an architectural question. Really simple setup. Let's say I have some Money value, and a script called MoneyTrigger that wants to tick up the value of money whenever the player walks into a specific trigger collider.

I also have a MoneyManager script that handles the modulation of Money, (getting money, spending it, saving the value etc).

How best should I connect the MoneyTrigger and MoneyManager? I'd rather not require MoneyTrigger to have to slot in the Manager class in the inspector. I'd also not want MoneyTrigger to do something like FindObjectOfType. Making MoneyManager a singleton is also not really preferable.

dawn nebula
#

Lots of layered noise.

#

Welcome to this series on procedural landmass generation. In this episode we create a grid of perlin noise values and render them to the screen as a texture.

The source code for this episode can be found here:
https://github.com/SebLague/Procedural-Landmass-Generation

If you'd like to support these videos, I have a Patreon page over here: http...

▶ Play video
fervent furnace
#

is your moneytrigger spawned in play mode? (not in world initially

dawn nebula
fervent furnace
dawn nebula
#

If the Manager isn't even in the scene, then nothing happens.

leaden ice
#

As long as you manage the subscriptions properly

quartz folio
#

I was about to say: though note that if you accidentally don't unsubscribe, static events are a fantastic way to get a leak

leaden ice
#

You could also use a ScriptableObject they both reference as an intermediary.

dawn nebula
#

Usually if communication is needed across a gameobject or to its children, I just use a serialized reference.
If communication is needed to a gameobject's parent, I use a UnityEvent or a C# event.
If communication is needed across "domains" (Game entities to Managers, Managers to UI etc), I use PubSub events.

white crater
#

anyone know what would be causing this

#

when i first pickup the weapon it goes into the right spot, but after i drop it and try to pick it back up it doesnt

dense tusk
white crater
dawn nebula
#

Will help cleanup some of those null checks.

pure sonnet
#

Hello i have an asset called Gamversion.asset and when making a build i want to increase the version(key value pair). How can i do that in Unity, i would like a static method i can call before making a bunch of builds?
Asset looks kind of like this

%YAML 1.1
...
MonoBehaviour:
...
  Major: 0
  Revision: 7 ```
sour atlas
#

using the advanced search, is there a way to select items with no components? I'm trying to batch grab all empty root gameobjects with no components attached. I can use "is:root is:leaf" to start, but not sure is there a 'not' option for e.g. 't:' ?

tepid plover
#

my files are gone in editor but in file exploror they are still there what happened help pls
i was just switching to webgl so i could put a build on itch.io for playtesting and they all dissapeared
but my game still works

#

someone please help me get htem back

tidal lichen
#

Have you tried clicking eye top right corner 😂

#

Eye icon*

tepid plover
#

yes😂😂😂😂😂😂😂😂😂😂😂😂😂😂😂😂😂😂😂😂😂😂😂😂😂😂😂😂😂😂😂😂😂😂😂😂😂😂😂

#

😂

#

😂

tidal lichen
#

Open and close unity ?

tepid plover
#

already done that

tidal lichen
#

Reimport the project. Do you know how to do that ?

tepid plover
#

right click and reimport all

tidal lichen
#

Yes

tepid plover
#

will that mess anything up though?

trim schooner
tepid plover
#

will everything still work as it did before

tidal lichen
#

I think so

deft thorn
#

Hello
i am having some trouble with the toggles

trim schooner
#

Re-import all just ... re-imports everything, it won't break anything

deft thorn
#

i have a toggle group outside
and when i click the toggle

#

it just doesnt work

tidal lichen
#

Sometimes it does

tepid plover
#

unity closed

#

is that supposed to happen..

deft thorn
#

like isOn field is false

tidal lichen
#

Yes now it will start reimporting everything

tepid plover
#

oh yea its going

#

ill report in a few mins what happens

light cloud
#

Hi guys, i'm kind of stuck and would need your advice.

I'm working on a personal project where i'm trying to blend two cubemap Skyboxes (day / night) and make it cycle from day to night in function of the IRL time (so the system time). I have the shader / blending part working. Altho, i'm stuck on the part where i need the "Blend transition slider" to slide to the right value. The slider can move between 0 and 1 max. So i had to normalized the time to get the right value between 0 and 1 (If it's 22:00 irl, it should be around 0.8 / 0.9 on the slider). But it doesn't seem to work right as it is 11:00 now and my cursor is randomizing around 0.003 and it should be around 0.5 since it's almost mid day. Since Day / night last the same, but Dusk and Dawn have smaller windows time, someone told me to use AnimationCurve, but can you really mix AnimationCurve and Shader Properties in a C# script ? To be honest i tried a lot of things and i think i confused myself.

Bonus : Mathf.PingPong is doing exactly what i want, but can't manage to make it happen slower (so related to irl time). Doesn't accept any surcharges of the function. Here is my C# code for the moment : https://hastebin.com/share/wataleneke.csharp

Thanks for the help

tepid plover
#

everything works now thanks

wise ermine
#

I'm getting the following error when trying to attach the script: The script is an editor script.

The script is not in the Editor folder, it worked just fine yesterday, and if I just copy the contents to a different script with a different name it works fine.
Is this some ridiculous problem with the metadata of the script?

fluid geyser
#

Where abouts in this code do I need to add a 'mathf.clamp' to limit the rotation when I move left/right?

trim schooner
tawny elkBOT
wise ermine
# trim schooner !code show it to us. You could also try just re-importing that file

TL;DR: The error was trying to attach a generic class that does not inherit from MonoBehavior to a game object. The error was message was completely wrong.

Tried it, tried resetting in git and whatever else, in the end the error was:

  • I was trying to attach a script to a game object.
  • The class in the script was generic and did not inherit from MonoBehaviour.

To this the editor raised the error "The script is an editor script", when I suspected that not inheriting from MonoBehavior was the issue I tried to inherit and it just said that the class name does not match the file name (even though in actuality the problem was that Unity does not allow generic classes to inherit from MonoBehavior).

languid hound
#

Why on this one particular day is this singleton null for a few frames at first? Trying to add to the interestingObjects list when OnEnable is called in another script says that the game instance is null

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Game : MonoBehaviour
{
    public List<InterestingObject> interestingObjects = new List<InterestingObject>();
    public static Game instance;

    public void Awake()
    {
        if (instance != null && instance != this)
        {
            Debug.LogError("Game singleton already exists! Destroying this copy...");
            Destroy(this);
        }

        else
        {
            instance = this;
        }
    }

    public void Update()
    {
        Debug.Log(instance);
    }
}
#

Awake does run before OnEnable which is why this is puzzling

fervent furnace
#

the scripts run like this:
A awake->A onenable->B awake->B onenable

#

awake runs before onenble is correct, but it may run after others onenable

languid hound
#

That's really annoying. Is there a way to change this at all?

fervent furnace
#

change script execution order/access it in start, start is guaranteed run after all awake were run

languid hound
#

Never really fiddled with script execution order but I'll have a look around. Cheers

late lion
#

The compiler is not included outside the editor. There is no reason for it to be included.

upper pilot
light cloud
#

Guys, how can that return 0 TI_Succ : (actual time = 14.0f)
hour = ActualTime / 12.0f;

upper pilot
#

ActualTime is an integer probably

light cloud
#

it is not

upper pilot
#

or hour is an integer

light cloud
#

Not too

upper pilot
#

then actuaTime is not 14.0f

light cloud
#

I swear, i tried everything, it still returns 0

upper pilot
#

then type 14.0f / 12.0f and see the result

light cloud
#

Returning me the right float with decimals. BUT HOW.

upper pilot
#

if 14.0f / 12.0f is correct

#

then that means "actualTime" is not 14.0f

light cloud
#

I'm gonna hard paste that here

#

look

#

[Header("24h Format")][Tooltip("24h format")] public float ActualTime = 14.0f;
[ReadOnly][Header("12h Format")] public float hour;

#

I even tried casting the variable in float by doing (float)ActualTime / 12.0f. Still 0

upper pilot
#

Use debugger

light cloud
#

No errors.

upper pilot
#

I dont mean errors

#

use debugger to see if your code is correct

light cloud
#

by putting breakpoints ?

upper pilot
#

yes

quartz folio
quartz folio
#

Well there you go. Not complicated

upper pilot
#

oh it serialized it to first value you set it to

#

[NonSerializable] would fix it probably

light cloud
#

Let me try

#

No way. Since when does it serialized it by default or either take the value from the inspector before the hard coded value ?

#

(It worked)

upper pilot
#

afaik any value you give it at the start and then compile will be serialized

#

it should only apply if you have a value serialized in the inspector(defautl behavior for public variables)

#
public int Hour;
[SerializeField] private int Hour;

Those are seriaized(visible in the inspector)

#
[NoSerializable] public int Hour;
private int Hour;

Those are not serialized(not visible in the inspector)

light cloud
#

So, to make my variable take the changes i do in the code, it would need to be hide in the inspector so no serializable ? what the hell

upper pilot
#

yes, because if you use inspector to setup some numbers, you dont want them to be lost when you make some changes in your code.

light cloud
# leaden ice Always

I don't remember having those issues on the projects i worked earlier. Changes to variable in the code was working

upper pilot
#

you can also not use MonoBehaviour if you dont want automatic seriaization afaik

#

You'd need to set [Serializable] on your regular class to enable it again

light cloud
upper pilot
#

public class Account : MonoBehaviour
{
   public Person person;
   public HiddenPerson hiddenPerson;
}

[Serializable]
public class Person
{
  public int age;
}

public class HiddenPerson
{
  public int hiddenAge;
}
tired elk
#

You probably didn't initialize it the 1st time, making it serialized to the type default value (0 here) and modified your code later. If you reset your component, it should go back to 14.

upper pilot
#

But the easy fix it so set defult values in Awake

light cloud
upper pilot
#
public class Person
{
  public int Age = 14;

  private void Awake()
  {
    Age = 23;
  }
}
leaden ice
light cloud
#

Not the whole code

tired elk
#

But if you want something to show without being serialized, you could consider doing a custom attribute drawer

light cloud
#

I did...

#

Maybe that's why..

upper pilot
#

Use Awake/Start or Init function to setup default values

light cloud
#

Na, ActualTime haven't my custom attribute drawer so can't be it..

light cloud
upper pilot
#

For debugging purposes use Debug.Log or draw on UI or have secondary variabe visible in the inspector.

tired elk
#

I didn't mean the issue could come from a custom attribute drawer, I meant that you could use one for the purpose of readonly data in play mode ^^'

light cloud
upper pilot
#

Why do you need them visible in the inspector?

#

I thought its for debugging purposes

#

during development

#

Unless you are actually using them with prefabs and such

arctic hornet
#

Hey all, I am looking for any information on creating a kinematic character controller. I have started dissecting various repos but am having trouble understanding some of the logic relating to collision detection and translation. Any resources would be greatly appreciated 🙂

light cloud
#

Nah, just want to see what variable have insides without having ten thousands log in debug console since i'm doing my code in the Update() function

#

So i decided to have a ReadOnly attribute drawer. Now it let me see the variables and what's inside

upper pilot
#

or w/e you want

#

also you can collapse logs(not recommended)

quartz folio
#

You can do that by switching the inspector to debug mode, and you can use trace points (breakpoints that don't halt) to print values in your IDE without adding logs

upper pilot
#

Oh I havent used inspector debug mode much, what is it good for?

light cloud
# upper pilot You can show debug.log every 5 seconds too

Yeah didn't thought about it tbh.. I wanted to have a space with all my properties changing in real time with the rights titles etc.. easier then having ten debug log hard coded that i'll had to erase or comment later if you know what i men

upper pilot
#

You shoudnt really have a lot of debug logs all at the same time

quartz folio
#

I rarely ever log anything, I just use tracepoints

upper pilot
#

tracepoints?

light cloud
#

Alright need to go back to business, thanks for the help

quartz folio
#

I only really use logs for things that need to be tested in release builds for whatever reason

#

(but I use Rider, not VS)

upper pilot
#

oh wow

undone mason
#

i have a problem

upper pilot
#

thats basically a debug log but without extra code 😄

quartz folio
#

With Rider it even logs to Unity's console now

undone mason
#

like here i am lerping player to that transform but it stops in 0.00001 before that

leaden ice
#

if you want to write the code this way, you should use either Vector3.MoveTowards or Vector3.SmoothDamp

quartz folio
#

Also... Is your IDE configured? That's a lot of the same colour

#

!ide

tawny elkBOT
undone mason
#

VS code

undone mason
#

moveforward worked with time.deltatime

#

Its fine now thanks

upper pilot
#

Is there a way to test if a property exists?

#

I am doing save/load system and if we add new properties I want to test for a property if it exists before I read it

#
string saveData = File.ReadAllText(filePath);
GameSave gameSave = JsonUtility.FromJson<GameSave>(saveData);
Gold = gameSave.Gold;
#

In this example, I would like to test if .Gold exists in the save file

fervent furnace
#

read the code of GameSave class

upper pilot
#
[Serializable]
public class GameSave
{
    public float Gold;
}
#

What do you mean?

tired elk
#

You mean to check if it exist in the save file ?

upper pilot
#

Save file might not have Gold saved if its from older version of the game etc.

#

yes

#

In Js you could do gameSave["Gold"] != null

#

not sure if its possible here?

fervent furnace
#

i remember json is compatible for this, wont throw exception

upper pilot
#

Guess I can only test and see :c

#

oh you mean that Json will return default value

#
            GameSave gameSave = JsonUtility.FromJson<GameSave>(saveData);
#

Because this will create an instance of a class and then overwrite values from save file

#

that makes sense if it works this way

#

So I dont need to do any checks

#

as long as I read from a class

leaden ice
fervent furnace
#

the value (data in disk) wont be overwritten

leaden ice
upper pilot
#

Yes that was the idea, to check if the json has a value saved

leaden ice
#

other serializers would let you do this, such as newtonsoft, but I don't think it's worth your time

upper pilot
#

yeah its not 😄

leaden ice
#

If you need to know this, you're better off with an approach like a separate bool field

upper pilot
#

I just need to test for default value and do nothing if its default

leaden ice
#

or a custom "Optional" class that holds the value plus a bool

upper pilot
#

that makes sense

#

but if I check for a default value I can just ignore it

#

if(gameSave.Gold == float.default) continue;

leaden ice
#

what if the value is legitimately 0 because the user spent all their gold?

upper pilot
#

the game will load it as 0

#

in game logic

#

save load is supposed to apply new values after the game is loaded

#

oh

#

its the same

#

if user spent all gold, it will be 0, but you do make a good point

#

if we start a game with some gold

hard viper
#

maybe load with negative gold

#

this way anytime gold is negative, you immediately know something is wrong, and can assert it is nonnegative

round violet
#

is there a way to debug and "see"/know what is modifying my player position
i checked all scripts, rigidbodies, animator and colliders, and my player is moving down in a moment were it shouldn't, i cant find what is "making it going down"
i also went in play mode and disabled one-by-one each component and gameobject of my whole scene and the issue was still there

hard viper
#

public const int UNASSIGNED_GOLD = -1;

hard viper
#

start the motion when the audio source’s play gets called

#

or coroutine to delay them

#

does the audio file have blank time

#

and are both audio source and player movement enabled at the same time

#

have you also looked into PlayDelayed?

#

i suspect this is an issue with your own script for managing the timing

#

but you said the audio file has a delay

#

if the audio file has a delay, how would unity know when audio is supposed to start

round violet
# hard viper is it dynamic?

"dynamic" what ? the player ?

also after some debug, removing the player rigidbody makes him not moving, so i think the issue is the rigidbody
the thing is, the gravity is disabled, and when disabling my c# script it still goes down

what could make my rigidbody go down ?

hard viper
#

i feel like the audio file should start with no delay, and delay is added via code, because then you can’t make the delay shorter

#

also moving objects so music will start at the right time is a very hacky solution

round violet
hard viper
#

still struggling with assembly definitions to get access to scripts in Packages. is there an example of someone defining this?

#

I tried making an .asmdef which references asmdef and dll from Packages, making an asmdef in my Scripts folder and setting it to reference the packages asmdef above. but idk what I’m doing wrong

tired elk
#

Did you put the .dll in the right array ?

hard viper
#

what do you mean?

tired elk
#

There's Assembly Definition References and assembly references

hard viper
#

currently have no assembly reference assets

tired elk
#

The dll is supposed to be put in the Assembly References one

hard viper
#

in my packages asmdef, i click override references to be able to add some .dll. and that asmdef also contains references to some asmdef files, which I think are in packages

tired elk
#

It's the part that handles "external stuff"

hard viper
#

oh

#

let me get this straight. I’m going to just start by deleting all the of asmdef I made to have a blank slate.
I make an assembly reference for externals, and fill it with references to things in my Packages folder. Then I make an asmdef in my own script folder (at root), and set it to reference my newly made external packages reference?

#

you’re telling me this should work?

tired elk
#

You should have something like this

#

The 1st part is asmdef you define yourself mostly

#

The second is compiled stuff such as dll

hard viper
#

and this is what my script folder asmdef should look like

tired elk
hard viper
#

i have watched several videos, but most of them glance over the external package part

#

they just drop some asmdefs into their folders, and go “ta dah”

tired elk
#

ah

hard viper
#

that’s why i’m confused on how to execute

hard viper
# tired elk You should have something like this

i think i’m a bit confused. this would be one asmdef in my root asset folder, it takes an assembly def reference which is an asmdef in my scripts folder. and as assembly reference I put my Packages .dll?

heady iris
#

if you need to refer to a precompiled DLL, put it in Assembly References.

#

if you need to refer to a DLL that unity is going to generate when it compiles the game, put it in Assembly Definition References

hard viper
#

and I do not need an assembly definition reference file to do that?

#

or maybe I should just make an assembly definition reference file as shorthand for that big list of dlls? Knowing this file isn’t actually needed?

indigo hound
#

Hey there, so in my game you can have different powerups. Some of the powerups grant new abilities like let's say hovering or climbing walls, which other powerups dont have. My question is regarding state machines. Would it be best to make a state machine for each individual powerup or not?

hard viper
# heady iris to do what?

to reference all Package dlls. I mean an assembly def reference can just be a convenient bucket for all the dlls, which other assemblies could reference manually OR just reference my assembly def reference. Is this accurate?

heady iris
#

there's a name collision there

#

An Assembly Definition Reference asset is used to put another folder into an existing Assembly Definition asset

hard viper
heady iris
hard viper
#

I would have a powerup state enum, and potentially one state machine, which lets you know which states you can go to on different triggers

heady iris
#

assembly definitions have "Assembly Definition References" -- a list of other assembly definitions -- and "Assembly References" -- a list of precompiled DLLs

heady iris
#

If A references a bunch of assemblies, and B references A, then B will see all of those assemblies

hard viper
heady iris
#

but I would want to check that

hard viper
indigo hound
hard viper
#

fire mario ignores mushrooms, and turns to super mario when hit, for example.

indigo hound
#

Yeah

heady iris
#

you must explicitly reference every assembly you use

#

I created Foo, Bar, and Baz, which were in FooAsm, BarAsm, and BazAsm

#

BarAsm referenced FooAsm and BazAsm referenced BarAsm

#

Baz couldn't see the Foo type.

hard viper
#

point being, the one big state machine can be made by tacking on logic from each individial powerup SO. or you can put like a power level int system where “if new powerup level > current powerup level, ignore”

#

that is more restrictive, but depends on what you want to make, since you could follow mario rules, or do whatever

indigo hound
#

I'll see what works best for me, but I think the enum fields you mentioned are gonna work the best

hard viper
#

you could also use a different enum to put powerups into different caragories, and allow interchanging between powerups based on category

latent latch
#

I'd do like two sets of enum states if powerups affect movement

heady iris
hard viper
#

(enum to put powerups into different caragories, and allow changing powerup state based on category)
like “helmet type” (shellmet), “mid level” (super shroom), “high level” (fire flower), “override all” (Pballoon)

latent latch
#

jumping is already a state, but if you've a powerup that modifies the jump than you need to check a powerup state

heady iris
#

Note that, by default, every Assembly Definition asset references every precompiled DLL, so this only matters if you turn on "Override References" and manually choose the ones you want.

hard viper
indigo hound
latent latch
#

ah, guess you can implement ICompare against it all

#

assumign some powerups have a priority

hard viper
#

depends on how mario like he wants it, vs making up his own rules

hard viper
#

which you really want to avoid

indigo hound
#

Alright thanks for the tips, I'm gonna see what I can do!

hard viper
#

good luck

indigo hound
#

thx!

narrow summit
#

Anybody has some handy code with them which allows to extend the editor toolbar to make a dropdown (not multiselect) like this. Basically another one besides this

hard viper
#

specifially, I cannot see attributes in Naughty attributes

heady iris
#

References aren’t inherited. I spoke incorrectly when i first answered

hard viper
#

woah, that got rid of a bunch of errors

#

so you're telling me every one of my asmdefs needs to manually call out NaughtyAttributes?

#

can't I make a reference to automatically include all of my little packages centrally?

tranquil canopy
#

You could give it a GUILayout.Height

hard viper
#

because this wouldn't scale to a project with lots of asmdef

glossy mortar
#

What’s the difference between C# and Python?

latent latch
#

syntax

hard viper
#

as far as I understand, I think assembly definition reference just makes the contents of one folder count as though it is in the folder of the referenced asmdef, as far as assemblies are concerned

hard viper
glossy mortar
fervent furnace
#

i like this answer

hard viper
#

it's a simpler question to ask what they have in common

#

they are both turing-complete programming languages used in modern day.

glossy mortar
#

Tell me some diffences

fervent furnace
#

literally everything is difference, the only common probably is they are programming language (or other one is snake)

tranquil canopy
floral hearth
#

how do i download files of free unity assets

#

on the website i dont see a download button

fervent furnace
#

not code question

#

open you editor and import it

floral hearth
#

yes but i dont have the files

glossy mortar
hard viper
#

This makes my code work again. Is there a way for me to make a more central collection of references to asmdef of packages I use, without defining them in every single asmdef I make for my own scripts

fervent furnace
#

python and c# support control flow statement

#

btw google before you ask

hard viper
#

because they are different languages

#

it's like asking what is the difference between spanish and chinese

stark sinew
tranquil canopy
stark sinew
#

In your Code, you are using GUILayout.Height for one of the boxes but not for the other one, why not simply use the same height for both?

#

Another thing you could do is to have a horizontal layout with a given height and make both boxes be a vertical layout with ExpandHeight inside it.

tranquil canopy
heady iris
#

But you haven’t shown us an Assembly Definition Reference asset

heady iris
stark sinew
hard viper
#

I made everything work now, but I think i need a better way to scale it.

#

putting this asmdef into my root assets folder makes my whole project work. but I want to be able to add asmdefs down below without copy-pasting all those asmdefs every time

stark sinew
# tranquil canopy lemme try

Pseudo Example

BeginHorizontal(GUILayout.Height(...));

BeginVertical(GUILayout.ExpandHeight(true)); 
// Left Content
EndVertical();

BeginVertical(GUILayout.ExpandHeight(true)); 
// Right Content
EndVertical();

EndHorizontal();

I think it should work even better without specifying a height in the Horizontal layout, but not sure, I'm not in front of my PC rn.
Has been a while since I did Editor Stuff like that, but I remember it being pretty easy to Layout

tame spruce
#

Hello all. I'm releasing a .unitypackage and it relies on TMP. What's the best practice around that? Should I do, in my package.json, this:

  "dependencies": {
    "com.unity.textmeshpro": "3.2.0-pre.7"
  },

And, even if I do that, I still get that pop-up that tells me to import TMP Essentials, and creates a TextMesh Pro folder under my Assets root folder.

In order to skip this step, can I just ship TextMesh Pro folder within my package? Could that lead into more problems?

stark sinew
#

I'm not sure, I think you aren't allowed to ship TMP within your package, but you'd be better off reading the TMP and/or AssetStore Licenses.

What's the problem in having the TMP pop-up appear when importing your package? It's pretty common that you have to "install" some dependencies when using external Packages.

Maybe, just to get some insight, you could download some free Asset that has TMP as it's dependency and see how they handled it, or have some kind of "Installer" window for your Package that would import TMP and your Contents with a single button click and without making the pop-up appear

tame spruce
stark sinew
round violet
#

hi
so i am calling a coroutine function to lerp between 2 positions (only changing the players y), this was all good and smooth

(2) i edited the function so my player is moving forward at the same time, because MovePosition wasn't affecting my player because the transform was overridden by this coroutine (this is my guess)

the code in the coroutine:

        float time = 0;
        float duration = 0.5f;
        float nbLoops = 0f;
        Vector3 start = transform.position;
        Vector3 goal = new Vector3(transform.position.x, (transform.position.y - 0.5f), transform.position.z);
        while (time < duration)
        {
            transform.position = Vector3.Lerp(start, goal, time / duration) + (new Vector3(1, 0, 0) * Time.deltaTime * _ziplineMoveSpeed) * nbLoops;
            time += Time.deltaTime;
            nbLoops += 1;
            yield return null;
        }

this is what i added for (2)

+ (new Vector3(1, 0, 0) * Time.deltaTime * _ziplineMoveSpeed) * nbLoops

why ?
because before doing all of this y lerping, i was doing the following to make the player go forward:

_rigidbody.MovePosition(_rigidbody.position + new Vector3(1, 0, 0) * Time.deltaTime *_ziplineMoveSpeed);

but it wasnt working as said in (2)

the issue is, at some moments while the lerp, my player is like teleporting a bit to forward/backwards, making the lerp not smooth

any suggestions ?

heady iris
#

You shouldn't be modifying the transform directly if you've got a Rigidbody on you

#

If you want to manually set the player's position, you can set _rigidbody.position or _rigidbody.rotation

onyx oriole
# latent latch or perhaps just make them both animation clips

thx i found it easier to do all the positional animations in code heres how i did the jump if anyone else needs it:

player.position = new Vector3(Mathf.Lerp(initial_pos.x, target_pos.x, interpolation),
** Mathf.Lerp(initial_pos.y, initial_pos.y + jumpHeight, Mathf.SmoothStep(0, 1, Mathf.PingPong(interpolation*2, 1))),** //This is the line that controls y value (jump)
Mathf.Lerp(initial_pos.z, target_pos.z, interpolation));

round violet
#

i still have the issue, and its arround the x manipulation

#

when i change only y i got no issues

onyx oriole
#

i used obs to record short clip of my problem

round violet
#

screentogif

onyx oriole
#

but this seems easier

unborn fern
#

Does anyone know how to make the camera background transparent so you can see the desktop and also clickthrough, but also make the ui clickable?

hard viper
#

you mean like a trojan?

valid jolt
heady iris
unborn fern
valid jolt
#

A hand an hour ago I'm asking for help please guys

sour atlas
#

Probuilder question - I'm having some troubles with UV editing, specifically being unable to move vertices, and scaling seeming to be centered on the origin (I think?) - video attached. Am I missing something??

simple egret
sour atlas
valid jolt
#

hi, pls

#

the AI instead of following the route, which the route has its own script, the AI car ignores it and only rotates in circles in the center of the map

hard viper
valid jolt
#

hi, I have a big problem, I'm making a 2D racing game, I'm with the AI driving, and when it's time to start, the AI goes all the way to the right, circles towards the coordinates of the folders where they have all the waypoints, instead of following the waypoints that are marked, I pass the 3 scripts that have to do with AI, the AIPathWay script, is the one that creates the line for the AI to follow https://github.com/eduarddo2888/scriptss/blob/main/AIPathWay.cs https://github.com/eduarddo2888/scriptss/blob/main/AICars.cs https://github.com/eduarddo2888/scriptss/blob/main/AIMomevent.cs

humble spoke
#

Hi guys. Can someone help me with these errors? I want to build APK

humble spoke
#

Okay

valid jolt
#

I really need help, I don't know what to do anymore to get some attention

leaden ice
knotty sun
#

Also after waiting a total of 10 minutes and asking for attention is a sure fire way of not getting any attention

knotty sun
#

nah, over entitlement problem 101

dawn nebula
#

What happens to Debug calls in build?

#

Does the engine actually call shit or does it know to just do nothing?

#

Like if I construct a string and throw that into a Debug.Log, the string construction definitely still happens regardless.

#

Right?

somber nacelle
#

Debug.Log still prints in a build, it just prints to the player log

#

but if you go and manually change the setting that makes it work in builds, then yes the string is still constructed. the method just doesn't do anything with it afaik

knotty sun
leaden ice
#

if you care enough

dawn nebula
quartz folio
#

Another is to use the [Conditional] attribute

leaden ice
#

Tell us more!

knotty sun
#

better yet, implement your own conditional debug.log

quartz folio
#

Make a wrapper function with the Conditional attribute applied and call that instead

dawn nebula
quartz folio
#

I always have a build tool that sets the stack trace level for builds and resets it afterwards

#

(it is awful it's the same setting as the console window)

#

Because the stack trace is a major part of the logs' cost

dawn nebula
#

And just toss it to who needs it?

knotty sun
#

no, a static class

dawn nebula
knotty sun
dawn nebula
#

Logger for UI elements, game entities, managers etc.

quartz folio
#

Just have an atypical singleton then, and allow construction of instances

knotty sun
quartz folio
#

Also note, if you just use tracepoints instead of logs for debugging then you have a whole lot less to do if you want to clean up. Personally I keep logs in builds, just don't have stack traces on for info level.

#

Logs are where I get info about what lead up to an error in release builds

#

If I want to find something out in detail in another kind of build, the debugger can do that

#

Most of the point of a domain-specific logger is to add prefixes and formatted state

soft shard
# dawn nebula Logger for UI elements, game entities, managers etc.

You could make a static log and extend it to whatever classes you need it in, for example:

public static class GameLog
{
public static Log(this Behaviour obj, string context)
{
Debug.Log($"{nameof(obj)}: {context}");
}
}

public class SomeScript : Mono
{
void SomeFunc() {GameLog.Log("hi");} //outputs "SomeScript: hi"
}

You could also make a dictionary of the types if you really wanted to have different log files for different types though imo that may be overkill unless your doing very specific debugging

somber sparrow
#

so i just used linux to install unity on my chromebook. believe it or not it actually works but im getting a bunch of error codes all about events, did i forget to install something?

simple egret
hexed oak
kindred copper
#

I applied for a job and they sent me a unity project to code
They supplied an API (Below) and told me to complete the game of tic tac toe.
I was unfortunately rejected, they said that my code architecture needed more work and that it could have been more abstract
I am kind of confused on what they mean and was hoping someone could look through my code and let me know what can be improved in the architecture or in general

UserActionEvents

  • UserActionEvents_TileClicked
  • UserActionEvents_StartGameClicked
  • UserActionEvents_LoadStateClicked
  • UserActionEvents_SaveStateClicked

GameView

  • ChangeTurn
  • StartGame
  • SetTileSign
  • GameWon
  • GameTie
  • ChangeTurn
  • StartGame

https://pastebin.com/raw/hvBVSLBt
I also wrote GameStateModel which is a class with properties so that I could serialize and deserialize specific variables in my class, i didnt include it because I didnt think it was important. if it is ill include it.

latent latch
#

I don't know what people expect from a game like tic tac toe lol

kindred copper
#

me neither I was caught off guard when they said the code needed improvement in its architecture I really thought I did a great job

hard viper
#

is there a way to make my project tab show all .asset files tied to a specific SO class?

latent latch
#

mostly interviewers who have zero coding knowledge and are going back a sheet of paper looking for buzzwords

hard viper
#

synnergistic assemblies

#

team-oriented githubs

#

My biggest weakness is dealing with Burst Intrinsics

kindred copper
#

alright ill take what they said with a big grain of salt and just move on >.<
Also transformice was a great game, your pfp really sparked some memories LOL

#

and thanks ofc 🙂

latent latch
#

looks fine to me honestly /shrug

hard viper
#

My old boss once asked me to deal with an extremely complicated Dynamically Allocated Array. It took me a few days, but I eventually came back to him with a complete implementation of a Doubly Linked List of Structs.

#

And everyone clapped

hexed oak
#

They probably just wanted you to have a middleman class that calls an interface that defines those methods
UserActionEvents_TileClicked
UserActionEvents_StartGameClicked
UserActionEvents_LoadStateClicked
UserActionEvents_SaveStateClicked

and then have your GameBoardLogic class implement that interface (which it does anyways...but just doesn't derive from an interface)

hard viper
dawn nebula
hexed oak
#

"Dynamically Allocated Array"
so... an arraylist? lol

hard viper
#

just wait until I hit him with the unsigned longs

dawn nebula
#

I always wondered why LinkedLists were featured so prominently in early programming education.

latent latch
#

worst ones are those asking you to do some specific binary trees or some recursive stuff

somber nacelle
dawn nebula
#

Considering they're pretty awful.

latent latch
#

and im like let me just google real quick

warm swallow
#

where is the best place to post a specific unity question here?

quartz folio
#

!support

tawny elkBOT
#
Where can I get help?

Take a look at #🔎┃find-a-channel

:warning: This is not a channel for official support.

Please do not ping admins, moderators, or staff with Unity issues.

warm swallow
latent latch
warm swallow
#

ok thank u

quartz folio
dawn nebula
quartz folio
#

I would be doing tic tac toe with bitmasks, but there's nothing wrong with the above approach 😄

warm swallow
kindred copper
#

Thank you again for your input guys 🙂
You have the appriciation of some random person on the internet now

hexed oak
#

what like a 2D array of bits and each move masks the coordinate?

simple mountain
#

can somoene here help me with my open gl code?

latent latch
#

unless it's specifically using Unity's Mesh library