#archived-code-general

1 messages · Page 358 of 1

cold parrot
#

Worst idea in anyone’s career who ever tried

merry ibex
#

for context im trying to add playfab into unity
it stores my email address as a string in one of the scripts
im after a way to hide it from being accessed anywhere

spare island
#

is your email address really that sensitive

cold parrot
merry ibex
spare island
#

if nobody knows its there they wont look shrug

#

or care probably

cold parrot
merry ibex
#

thanks

spare island
#

yeah plenty of burner sites or make it on yahoo and they really wont want to email you

#

"who tf uses yahoo? must be a burner"

merry ibex
#

not my main one so its fine

spare island
#

that wasnt your first idea? :l

merry ibex
#

i didnt realise until after i installed the package it stored my email address

spare island
#

trying to use IL2CPP as an obfuscator of some sort

#

which btw even if you hid your email from that file it would still be stored as a string somewhere

merry ibex
spare island
#

It can't

merry ibex
#

yeah

#

someone told me it turns it into c++ and binary

#

but then it can deassembled into pseudocode anyways

spare island
#

Libraries need to have public names so that they know how to call the methods

#

so the names of the methods and such will all still be visible

merry ibex
#

ohhh

#

that explains how someone made a mod of the beta of it then

#

tysm for the help btw

spare island
#

beta of what?

spare island
#

using unity engine is like 2 steps from a public repo lmao

merry ibex
#

back then I was using github servers but im transitioning to playfab as its more secure

spare island
#

or is your email the only thing

merry ibex
spare island
merry ibex
#

or by using github as servers people could redirect the game to their server and get access to stuff

knotty sun
#

Guys, you are steering very close to a topic we do not discuss here

merry ibex
#

aight sorry

civic isle
#

thought that was a solid one

primal raptor
#

is the one in middle a function ? If so why is written like this +=() =>

knotty sun
#

yes, that is called an anonymous function

#

and, in that use case is very bad practice

#

oh, yes, why is it done like that? I can only assume the person who wrote the code did not know what they were doing

primal raptor
#

what is the better way of writing it?

knotty sun
#

by writing a proper method which can be subscribed and unsubscribed to the event

primal raptor
#

can you show me how its done?

knotty sun
#

sure, if you post that code properly

#

coz I aint gonna retype it all

primal raptor
#

AuthenticationService.Instance.SighnedIn += ()=>{
Debug.Log("test");
}
await Authentication.Instace.SignInAnonymoslyAsync();

#

you mean like this?

knotty sun
#

I meant all of it but that will do

#
AuthenticationService.Instance.SighnedIn += OnSignedIn;
await Authentication.Instace.SignInAnonymoslyAsync();
...

void OnSignedIn() 
{
    Debug.Log("test");
}

void OnDestroy() {
AuthenticationService.Instance.SighnedIn -= OnSignedIn;
}
primal raptor
#

void OnDestroy() {
AuthenticationService.Instance.SighnedIn -= OnSignedIn;
}

what does this part do?

knotty sun
#

unsubscribes the event when the class is destroyed
note the difference between += and -=

primal raptor
#

ohhh ok thanks alot

lapis pebble
#

I have a game where you control a ball by tilting the level course, trying to get the ball into the cup hole. The problem I'm having right now, is that my ball, which uses Rigidbody for physics and gravity - doesn't immediately respond to the player's tilting whenever the game starts. The ball only starts applying gravity when the plane is tilted very far. I tried to set the collision method to Continuous or Continuous Dynamic, but it doesn't change much. Any ideas?

knotty sun
hot steppe
#

i made a 2D snowboard game and I'm using left/right arrow keys to rotate the player. I'm using torque to rotate it. The problem is i built the project and when i start the game the player rotates really slow. But it works well in studio

lapis pebble
#

I had times where the ball wouldn't even touch the platform, or even go through it - and the ball would keep floating in the air, not reacting at all!

knotty sun
#

I thought you said it had a rigidbody, is it kinematic?

lapis pebble
knotty sun
#

sorry but there is no way a non kinematic rigidbody using gravity will 'float' so there must be something wrong with your setup

hot steppe
lapis pebble
knotty sun
wide terrace
hot steppe
#

oh sorry

lapis pebble
#

As I'll be checking all the colliders I have in scene - I also managed to record the problem itself:

#

Not sure if it will be that helpful, but maybe it will give an insight to what I'm trying to figure out at the moment

knotty sun
#

I dont know where your colliders are but that looks like they are not moving with the model

lapis pebble
#

Could the issue arise from the amount of vertices on certain game objects/meshes? My cup hole is the most complext object in the scene, as I have created it within ProBuilder

knotty sun
knotty sun
lapis pebble
knotty sun
#

no, thats ok, im only interested in the ball

lapis pebble
#

Did I show what was needed? Anything else I could help with?

knotty sun
#

Sorry, you need to expand the constraints and Info sections

lapis pebble
#

The same experiment, this time - the rigidbody component is fully shown from the beginning till end

knotty sun
#

Yes, you can see there between 19 and 25 seconds the ball should have speed at least from gravity but it does not.
Are there any scripts at all affecting physics or the ball?

lapis pebble
#

As of now, the project only has 2 scripts: one is for controlling the platform, the other is for rotating the camera

#

No custom scripts are attached to the ball game object at all. The ball has these components only: Transform, Mesh Filter, Mesh Renderer, Sphere Collider, and the Rigidbody (and maybe the default material if you want to consider it too)

knotty sun
#

Got it

your rigidbody is asleep

#

@lapis pebble

civic nymph
#

this is why I switched

leaden ice
#

it has to do with the event system.

civic nymph
#

alright you know what I'm a little lost on why I did it now too

#

there was a very good reason for it

#

I know that

leaden ice
#

sure but if you are going to decide "I'm going to switch to the new input system" then you should actually commit to doing that, including the costs of changing your code to the new system

lapis pebble
#

Also, another question if I could - is there another function to put it back into the sleep state, or is it better to just disable gravity whenever I want the ball to freeze/pause in time?

knotty sun
#

sure, check the docs, there is the Sleep method and the sleepThreshhold property

lapis pebble
#

I will check the docs, surely

#

Thanks again for the help!

knotty sun
#

np, gotta say in all my years of using Unity I've never had to wakeup a rigidbody

devout parrot
#

How do I get a character to rotate according to its local rotation? I have a character running around a planet, but when I try to do this to get the character to rotate:

transform.forward = Vector3.Slerp(transform.forward, input, Time.deltaTime * rotSpeed);

the script uses world vectors, causing the character to fall on its side when walking on the equator. Is there an elegant solution for this?

leaden ice
#

if input is indeed a world space vector, then the code would work as is. So it sounds like input is not a world space vector

#

If input is a local space vector then you would just convert it to world space before using it.

devout parrot
#

input comes from another script as such:

void Update()
{
  moveDir = new Vector3(Input.GetAxisRaw("Horizontal"), 0, Input.GetAxisRaw("Vertical")).normalized;
}
public Vector3 GetInput()
{
  return moveDir;
}
leaden ice
#

Also this code seems to be about moving not rotating

leaden ice
#

convert it to world space first, then you can use it in your other code.

#

Also make sure you actually want to move according to the player's orientation and not the camera's orientation, as those might be different and will result in very different behavior.

thorn crag
#

So, i am trying to get my game to pull up a windows system message, as a sort of meta thing (Like what OneShot does) but i keep getting an error with using the namespace "system.windows.forms" and i don't know what to do, help would be appreciated.

leaden ice
#

I have no idea what "OneShot" is

knotty sun
leaden ice
#

Sounds like something you would need to either import a DLL from or make a call out to some native interop code.

thorn crag
#

ok, thank you for letting me know

devout parrot
#

@leaden ice So, my character can walk from the equator to the north pole just fine, but any other direction still results in flopping around. Maybe I need a completely different solution here.

#

Also, I do plan to have a toggle between player-oriented movement and camera-oriented movement

civic isle
#

the code

devout parrot
#

@civic isle yes

civic isle
#

have you tried something like transform.rotate quaternion.lerp instead

#

im not a pro but it seems like an odd way to rotate to me

wide terrace
devout parrot
#

My issue with that is that rotation is already being set by a faux gravity script. If I try that, the gravity script will fight the player script.

#

@wide terrace Here's my gravity script:

public void Attract(Transform body)
    {
        Vector3 gravityUp = (body.position - transform.position).normalized;
        Vector3 bodyUp = body.up;
        
        body.GetComponent<Rigidbody>().AddForce(gravityUp * gravity);
        
        Quaternion targetRotation = Quaternion.FromToRotation(bodyUp, gravityUp) * body.rotation;
        body.rotation = Quaternion.Slerp(body.rotation, targetRotation, 50*Time.deltaTime);
    }
wide terrace
#

I see - interesting. Thanks!

civic isle
#

@devout parrot use a rigibody and lock rotation

#

to the side

devout parrot
#

The character already has a rigidbody with rotation locked on all axes

civic isle
#

lock the rotation in script in lateupdate perhaps

leaden ice
devout parrot
#

I have a partially working script now:

void Update()
{
  input = new Vector3(Input.GetAxisRaw("Horizontal"), 0, Input.GetAxisRaw("Vertical")).normalized;
  Debug.Log(input);
}
    
void FixedUpdate()
{
  transform.localRotation = Quaternion.Slerp(transform.localRotation, Quaternion.Euler(0, input.x*90, 0), rotSpeed * Time.deltaTime);
}

It can look left and right as expected, now I just need to get forward and backward working and I should solve this problem.

leaden ice
#

The other code you had was mostly fine you just needed to convert your input vector to world space

devout parrot
#

This script is attached to a child object of the player that holds the mesh. The main player game object has the rigidbody and handles the physics

leaden ice
#

Why not just:

Quaternion.LookRotation(input)```
#

Quaternion.Euler seems roundabout and... hard to work with here

devout parrot
#

...that actually worked better. All directions work now and i can walk on the sphere just fine now. Thanks for your help!

abstract sparrow
#

Could someone help?

NullReferenceException: Object reference not set to an instance of an object
SkillNode.Initialize (Skill skill) (at Assets/Scripts/SkillTreeSystem/SkillNode.cs:28)
SkillTreeManager.DisplaySkills (System.Collections.Generic.List`1[T] skills, UnityEngine.Transform column) (at Assets/Scripts/SkillTreeSystem/SkillTreeManager.cs:61)
SkillTreeManager.Start () (at Assets/Scripts/SkillTreeSystem/SkillTreeManager.cs:46)

Skill.cs is class without mono behaviour

somber nacelle
#

then skillNameText is null. show where you've assigned it

#

also !code

tawny elkBOT
abstract sparrow
somber nacelle
#

you have a condition that specifically checks for that

abstract sparrow
#
  • question, does prefab store references?
somber nacelle
#

it's also just skill in this case, not skill.cs because the cs file cannot be null

somber nacelle
abstract sparrow
#

this stuff is stored when i make prefab from thing?

somber nacelle
#

so long as you aren't attempting to reference an in-scene object and are instead referring to something within the same prefab or another asset then you can

opaque vortex
#

does anyone know how to code a API file I can give my users to upload their custom UGC content? I am trying to build it myself and it is very hard

abstract sparrow
#

ew, im stupid, i have panel with theese text's and buttons after i selected all of theese references in script i deactivated this panel

leaden ice
#

At the most basic level though, it's just a datastore hosted somewhere on the internet somewhere.

#

What to actually use depends on what kind of content you want to store.

compact fog
#

Less of a code question and more of an editor thing. But I am having an issue where a list on a scriptable object i created is being cleared whenever a change to a prefab that is attached to that object is added. Attached is the screenshot of the scriptable object.

#

Not a massive issue but majorly frustrating

somber nacelle
#

are you perhaps doing something in OnValidate?

leaden ice
compact fog
#

Nope, no editor changes or OnValidate calls

#

The only thing close to a editor change was i installed searlized dictionary addon that I am not using in any scripts but could that possibly be it?

leaden ice
#

not likely but techically any asset or plugin can cause issues...

Try restarting the editor?

compact fog
#

Ive restarted multiple times since i first noticed

leaden ice
#

You're not using Dropbox or something are you?

#

I do see you have Version Control - definitely lean into that

craggy pivot
compact fog
#

Man this is very annoying. It doesn't even really make sense. I have 4 instances of of the scriptable object, and its inconsistent on which is being cleared when a prefab is updated.

opaque vortex
leaden ice
opaque vortex
leaden ice
#

Depending on what you need

opaque vortex
leaden ice
#

Not sure what avatar data is but you could use S3 or something similar

opaque vortex
#

can that run async and with users able to upload/download content onto the server while playing?

leaden ice
#

Of course lmao

#

All that is client side stuff though

wide terrace
#

I've been using Backblaze for an S3 stand-in for various larger-data things recently... If you use Cloudflare to host the interface, data egress is free, which is super nice

opaque vortex
# leaden ice Of course lmao

wait, but how do you regulate content on it? I was going to seperate the content between age ranges, and graphic quality. Can it do that?

leaden ice
#

That stuff is all up to you

#

I'd probably use a SQL database for metadata

#

You're asking too much from general purpose tools.

#

You're going to need to write a web api

opaque vortex
leaden ice
#

Potentially moderation of some kind if you're doing age range stuff

opaque vortex
leaden ice
#

Well which part are you wanting help with specifically

#

Most of this isn't actually Unity related

opaque vortex
#

it is a literal extension to unity

#

I can show it if you want to see?

leaden ice
#

Adding extensions to Unity is well documented

opaque vortex
leaden ice
modern creek
#

I'm compiling (a mostly-empty project) with optimize for disk space and LTO for UnityWeb (WebGL for unity 6) and the linking is taking really long (20 minutes so far). Normal? The non-optimized build linking takes ~1 second.. I knew it'd take longer, but .. didn't quite expect this long

#

Also targeting wasm 2023 if that makes a difference

opaque vortex
onyx cypress
leaden ice
#

You're updating the destination when it's farther than 1, instead of less

modern creek
#

Anyone got a tip/idea for adding debugging text to the world? I'd like to staple some debug text in a specific place on a mesh.

I don't think I want to use UI since I'd need to raycast to the object and find some UI-space coordinate to display the text.. and move it around as the camera changes.. etc

I tried Handle but I don't think that's right, since AFAIK it only shows up in the editor, and I need some debug text in the build.

somber nacelle
#

use a world space canvas

modern creek
#

I don't understand. Just slap all of my world items under a canvas..?

somber nacelle
#

just the text you want to display in the world

modern creek
#

The Canvas/UI scaling is per pixel, and the world scaling is 1 unit = 1 meter..

somber nacelle
#

or there's the TextMeshPro component that is not for UI

modern creek
#

I want the text attached/near several 3d objects

#

hm, lemme look

somber nacelle
modern creek
#

So, cameras are moving all around.. I can stop them for what I'm working on, but I was hoping do throw a bunch of 3d objects down and print some debug information on/near each.

I didn't want to do a bunch of.. like.. figuring out where on the screen to display the text, though.. ie, calculating a screen position based on a world position and camera.. I was sorta hoping I could just slap a TMPro or Debug.DrawText or something on the item

somber nacelle
#

right and you can do that using either of the suggestions i gave

modern creek
#

Hm, there's a gap in what I'm trying to say or what you are and my brain. 🙂

#

Lemme do some screenshots, maybe

somber nacelle
#

both of the suggestions i gave are in world space

modern creek
#

ok, hang on, lemme just play and see

#

I've never used the non-UI tmpro

somber nacelle
#

neither of them have anything at all to do with screen space or the camera. they exist in world space like your mesh

modern creek
#

OK - so I have my hierarchy parented like so.. no canvas on the world space items.. Do I just change the (existing) canvas to a world space canvas?

somber nacelle
#

if the existing canvas has the stuff you want to display in world space, then yes. otherwise make another canvas and set that one to world space. then you just adjust its size/position accordingly

modern creek
#

k.. standby, just playing around with the non ui tmpro

somber nacelle
#

if it is just text you want to display, then that should be all you need. if you want to display any other UI objects, then you will need to go with a world space canvas

modern creek
#

Yeah, just text for now.. just debug text

#

amazeballs, thanks

#

I didn't even need to change the canvas to worldspace.. just throwing the tmpro item on the 3d object and wiggling the rotation and scale and stuff around was sufficient

somber nacelle
#

right because the non-ui version of the TextMeshPro component does not belong on a canvas because it is . . . not UI

#

the canvas is only for UI

modern creek
#

yeah, gotcha.. I forgot there was a non-UI textmeshpro item.. I've typed "TextMeshProUGUI" probably 10,000 times in the past 3 years even 😛

#

My brain just went to.. using that component and figuring out a simple way to figure out where on the screen to render it .. instead of just making an actual TMPro component and putting it in the world, done

waxen jasper
#

hey gamers, I'm making a spider. to anchor its "feet" to the ground I activate hinge joints. Id like the joint angles (for the foot ancho) to reflect the surface. I think I'm on the right track but maybe not. You can see the "foot anchors" in this image, basically I'd like them all to be the same, independed of the leg angle (given the surface it the same angle). If i can figure this out i can smooth my walking. (this spider realistically walks)

I'm on the right track - no pun -, I'm using raycasts and normals to assign the hinge limits. but I've lost the plot

modern creek
#

@somber nacelle thx again.

#

just wanted an easy way to see cartesian/axial coordinates on all my hexes at a glance

terse rain
#

Hey, I'm using XR and trying to pass an objects name on the OnSelectEntered Event in the hand's XR Direct Interactor. Is it possible to send the paramater that changes depending on whats picked up?

warm badger
#

can i draw different meshes at specific positions using DrawMeshIndirect? i have some positions stored, some of the positions are for grass, some are for flowers...can i draw these two meshes at their specified positions at once or do i have to call DrawMeshIndirect 2 times with their respective positions buffer?

somber nacelle
#

assuming you are actually referring to RenderMeshIndirect or RenderMeshInstanced (there is no DrawMeshIndirect, though there is an obsolete DrawMeshInstancedIndirect), it only takes in a single mesh because it is meant to render mulitple instances of the same mesh so you'll have to call it for each mesh you'd like to render

warm badger
storm wolf
#

Is there any way to trigger the cursors “clickable” pointer state through code? Like for windows when mousing over a hyperlink the pointer changes to the click hand. Everything I find is just about Cursor.SetCursor which I theoretically could do but I am moreso asking for an easier way than changing the texture manually. Is there some api to use? Not sure how i can do this cross platform as well. Sure I could take the windows “hand” pointer sprite and set the cursor on mouse over. You see where im going with this, thanks!

twin egret
#

is anyone here familiar with transform matricies? i’m up to some weird tilemap shenanigans

#

i’m trying to convert a tilemap that i imported from godot to unity, and godot stores three transformations: flip h and v, and transpose. i’m looking a matrix4x4 to get a start, but i’m not sure how i can apply certain transformations. it seems like there’s a transpose function already, but flipping h and v?

rough fern
#

I need to make a planecast, or in other words "wide" raycast, is there a not crazy resource expensive way?

lean sail
rough fern
#

And the reason it needs to "sweep" from a direction is because I need to know in what orders it hit the colliders

rough fern
#

I guess it should, thanks for the solution

dawn nebula
#

Would effectively turn it into a Planecast.

lean sail
#

a plane spans infinitely, so its not really the same but it doesnt sound like a "planecast" is even needed

rough fern
#

I guess planecaset would be the wrong way of calling it. Line cast? Wide raycast? But since box cast is here I'll try that

dawn nebula
vital robin
#

😢 Help...

when I execute this line of code

if (speakerData && isVisible && character)
{
Show();
}

this takes me into weird file called class PlasticApp and execute IsPlasticStackTrace() and execute bunch of other weird internal files and crash leaving this error message:

NullReferenceException: Object reference not set to an instance of an object
DIALOGUE.ConversationManager.HandleSpeakerLogic (DIALOGUE.DL_SPEAKER_DATA speakerData) (at Assets/_MAIN/Scripts/Core/Dialogue/Managers/ConversationManager.cs:114)

if statement just checks whether character has to enter the scene and make sure that character is not already visible or revealing

and Show(); is just altering alpha value to reveal the character.

I don't know why this 3 lines of code takes me to that weird files and crashes... Please Help

knotty sun
#

wdym, you don't know, these are obviously assets which YOU imported into your project

simple egret
#

The debugger is running package code that's unrelated to your error.
Look at the stack trace you posted to see where the exception was thrown.

#

ConversationManager.cs:114
ConversationManager, line 114

vital robin
#

Thanks, I didn't know debugger can run packages that's unrelated to my error.

#

I'll try spotting errors in ConversationManager, line 114

soft shard
ancient magnet
#

Quick question: I see this a lot in "more professional" code, when someone makes a list of something they often use, for example, private List<Collider> collider = new List<Collider>();, instead of just private List<Collider> colliders. Why would you do that, does it even make a difference?

simple egret
#

If you try to use the second one as is, you'll get a NullReferenceException

#

Like when trying to add an element to the list (there is no list, the variable will contain null by default)

knotty sun
soft shard
#

Sometimes the second option can be useful, in a case where you might want to initialize the list in a function that also populates it, rather than initializing it when its created, if the same case means the list might never get used

onyx cypress
storm wolf
queen saffron
#

Hello,
I've installed both packages XR Hands and XR Interaction Toolkit. However, the movement of the character is too slow and i was hoping to increase the movement speed. is there any slot i can store a speed movement or i need to create my own script for that?

leaden ice
#

but - presumably on that script

#

Probably here

queen saffron
#

i believe it is through this input action map

#

i've added this component hoping that move speed would do the trick but nothing changed

leaden ice
#

oh wait yes, it's the continuous move provider that does it

queen saffron
#

that is the whole inspector view of locomotion system

leaden ice
#

You have two different continuous move providers on here

queen saffron
#

i just recently added the deviced based

#

neither one of those are doing the trick

#

or is it only applied through XR devices and not through XR simulator?

swift falcon
#

is coding a 2d game easy?

leaden ice
#

I mean that's what they do

swift falcon
#

im new

leaden ice
#

any game will be hard when you first start out though

#

because you will need to learn

swift falcon
#

im thinking of making a science game as a start

leaden ice
#

then you will have to do some learning and struggling

swift falcon
leaden ice
#

that's up to you ¯_(ツ)_/¯

queen saffron
#

Like i don't have VR devices to connect it out to the project. does continious move provider work only on VR devices?

swift falcon
leaden ice
tawny elkBOT
#

:teacher: Unity Learn ↗

Over 750 hours of free live and on-demand learning content for all levels of experience!

queen saffron
#

i'm doing my project via XR simulator which installed as extension from XR Interaction Toolkit

swift falcon
deft dagger
#

hey i have some questions about making a build in unity, when i choose certain scenes in the scenes in build section, for example if i didnt choose any of the scenes and did a build shouldnt the build be so small ? but now im trying that and the build is 600 mb, why is that ? and how can i fix that

cosmic rain
hasty wave
#

I don't understand? Why can't I remove a point from a polygon collider 2d???

leaden ice
hasty wave
leaden ice
#

I thought you were asking about how to do it in code

spare dome
hasty wave
#

oh my bad, I kinda don't know where to ask...

spare dome
#

your good dude 👍

primal wind
#

Is there an event that happens just before a domain reload? I need to save some process IDs with SessionState

primal wind
#

Thanks

simple ridge
#

Hi all, is their a way to sample the same values from the gradient noise node in a shader within scripts? I am using the gradient noise to add some height displacements to different cells on a grid, but then also need to move the player up or down depending on the height of the cell. I was going to do this in C# as I would like to do some other things with these values too. Is this possible?

deft dagger
#

hey guys i have a problem about builds and i dont know where to post it

deft dagger
#

its just that the build i make comes bigger than its supposed to be

#

it says that the base is ### mbs which i dont understand where they come from

rigid island
#

also doesn't seem like a direct code issue

deft dagger
# rigid island > bigger than its supposed to be and whats it supposed to be?

all the scenes combined in the addressables should be something like 900 mb give or take, but after the build it says something about the base of the build or something being 500 or so mb and the build ends up being 1500mb, but when i check to see what is taking up the 500 or so mb in the build through the editor log i see that it says the assets are 900 mb

rigid island
deft dagger
rigid island
rocky jackal
#

Why doesnt the string.Replace method work ?

leaden ice
rocky jackal
#

oh, thank you

leaden ice
#
string result = sceneName.Replace("Entry", "Main");
Debug.Log(result);```
rocky jackal
#

now its working

leaden ice
#

strings are immutable in C#. So anything that modifies a string will always return a brand new one

rocky jackal
#
sceneName = sceneName.Replace("Entry", "Main");

Is this a bad idea ?

leaden ice
#

it's fine

#

I mean I think this whole string manipulation thing is possibly a bad idea

#

but, that in particular is not

karmic pine
#

My xr Plugin Managment is gone

#

Can someone help about this problem

#

Nobody?

rocky jackal
leaden ice
karmic pine
#

yes

leaden ice
#

do you have any errors in console

karmic pine
#

apparantly i need to delete the global cache of xr plugin management

#

but how

#

{hi}

#
Cool For Now on Im typing like this
#

Guys can you help me find preferences

#

anyone?

somber nacelle
#

that's not a code question, but it is in the Edit menu

karmic pine
#

but i dont seem to find it

spring creek
leaden ice
sinful night
#
playerID in body must match authenticated player```
After creating a lobby, when I exit play mode, start the game again and try to create a lobby, I get this error.

Here is my code https://pastebin.com/LbwDqQzs
#

I'm pretty sure playerData.Id and AuthenticationService.Instance.PlayerId definitely match. Actually, I couldn't find what the error meant by "playerID in body".

static matrix
#

so i've now learned how to make editor buttons

#

which is great
but I fear I shall spend an eternity making more

urban lintel
#

Could someone tell me whether i've over-engineered this piece of code? I wanted to essentially have a system where an input (e.g. [1,5,2,4,3]) corresponds to different spells/bullets in the game being fired in that specific sequence. These spells don't necessarily have the same behaviour, as one could be a slow moving projectile while the other could be a hitscan or something similar.

Since all of these have different stats and cooldowns, I've put this specific data in general purpose ScriptableObjects. I've also created a class that when passed an id or enum, will give you the appropriate scriptableobject (e.g. you ask it for Fireball, it gives back the attributes for Fireball). My next plan was to make it so that each of these scriptable objects also has a field for the Prefab which it corresponds to (e.g. Projectile, Hitscan, AoE effect etc.), which will then be picked up by the interpreter and instantiated. So for code, it's something like:

    BulletAttributes bulletAttributes = this.bulletAttributesRepository.Get(bulletType);
        
        GameObject bullet = Instantiate(bulletAttributes.prefab, position, Quaternion.identity);
        bullet.GetComponent<IBulletScript>().SetDirection(direction);
        bullet.GetComponent<IBulletScript>().SetAttributes(bulletAttributes, parent.GetComponent<PlayerStats>());

The idea being that this class picks up the prefab based on scriptable objects, and simply passes on the attributes to the prefab (this way the projectile's damage is not determined by the prefab but by the stats of the player and the spell). And various prefabs could then have different scripts for different behaviours. Does this seem about right for what i've described? Should I also maybe link the behaviour of the projectile to the ScriptableObject, rather than tying it to the prefab? Any other constructive criticism would be greatly welcome! Many thanks

thin aurora
#

Also, consider splitting up your code so errors are clearer. Instead of inlining parent.GetComponent<PlayerStats>() place this in a separate variable and use that instead. It's clearer with errors and generally more readable

urban lintel
#

Good calls, I've just changed those 🙏

steady moat
#

If you have a spell that shoot two projectile for example, you can handle that there.

#

Or if you have spells that do no shoot bullet.

urban lintel
#

oh, I didn't actually know I could do that with scriptable objects

#

I just assumed they're more like data objects of sorts, kinda unclear what they are exactly since im neither from a gamedev nor unity background

steady moat
#

You can have function in a scriptable objects

urban lintel
#

that'd actually simplify stuff a lot I think, i'll look into it

steady moat
#

I usually instantiate a POCO that handle the whole ability.

#

It makes it easier to have ability with casting time or different activation at different time.

#

Things like shoot 1 fireball, follow by 3 others 1s latter.

urban lintel
#

would you by chance have a reference or code example of using scriptable objects in this way (i.e. where they are responsible for instantiation of the gameobject), I've still got some gaps in my knowledge and i've seen scriptableobjects used mainly as data containers in the examples i've seen

steady moat
#
public class FireBallAbility : AbilityDefinition {

  public override void Instantiate(...) { ... }
}

#

What I prefer is to do something like:

public class FireBallAbility : AbilityDefinition {
  public class Ability : Ability {}
  public override Ability Instantiate(...) { ... }
}

urban lintel
steady moat
urban lintel
#

does AbilityDefinition here inherit from ScriptableObject

steady moat
#

yes

quiet flower
steady moat
#

If you have other system it can use it

#

Limit on ability that equipped, categories

quiet flower
#

Tought the { was at the same line , was wondering if I had fully learnt C# lmao

steady moat
#

If you do not know inheritance you need to review things.

urban lintel
#

hmm, okay I got something going:

//File1 - Bullet.cs (Ability equivalent)
  public abstract class Bullet : ScriptableObject
    {
        public float speed;
        public float cooldown;
        public abstract float Instantiate(GameObject player, Vector3 position, Vector3 direction);
    }

//File2 - NormalBullet.cs (Fireball equivalent)
   [CreateAssetMenu]
    public class NormalBullet : Bullet
    {
        public override float Instantiate(GameObject player, Vector3 position, Vector3 direction)
        {
            var bullet = Instantiate(prefab, position, Quaternion.identity);
            bullet.GetComponent<BulletScript>().SetDirection(direction);
            return cooldown;
        }
    }

//File3 - Shooter.cs = The shooting monobehaviour that handles input. Shoot is called based on player input.
    private void Shoot()
    {
        if (_shootCooldown > 0)
            return;
        var position = transform.position;
        var bulletType = magazine[_currentBulletIndex];
        var direction = Camera.main.ScreenToWorldPoint(Input.mousePosition) - position;
        var bulletAttributes = this.bulletAttributesRepository[bulletType];

        _shootCooldown = bulletAttributes.Instantiate(parent, position, direction);
    }

The bulletAttributesRepository in this case has an inspector where I pass enum+ScriptableObject instances, so I can create like 3 different assets of NormalBullet as upgrades of one another and just associate those with different enums. Sorry if this last part was unclear but i hope this is roughly what you had in mind?

#

this works fine for what that's worth, though some stuff could use polishing (like the way im handling the cooldown)

quiet flower
#

Inheritance with classes , to inherit a class ?

#

Or you talk about something else

#

My English isn’t that good

#

Sorry if I don’t fully understand what you’re saying

quiet flower
#

But I don’t know what Instantiate is

#

If you know

steady moat
urban lintel
#

yeah naming should definitely be changed, im already confusing myself

#

would you say the rest is about right? I'm not experienced enough to know about any shortcomings of this, but I do already love how scriptableobjects can be tinkered with during runtime and then persist after stopping the game. Now I assume I'd probably want a new class for every single ability, unless that ability happens to have the exact same behaviour but different colour/speed/cooldown etc. E.g. with this i could create a fireball, a big fireball, an always-critting fireball etc., so long as those are fields in the attribute definition. Then if i suddenly need a seeking fireball, i'd probably be better off creating a new ability definition or something similar

steady moat
#

For runtime*

urban lintel
#

in the sense that the data inside shouldn't be changed by the runtime you mean? yeah that's fine

steady moat
#

The behave differently in a build and editor on that aspect.

urban lintel
#

i just mean as in tinkering with it

steady moat
#

Just making sure.

#

The rest seem like a good start

urban lintel
# steady moat Just making sure.

just to sort of be clear on that, what you mean is that for example I can store the maximum life of the player on a scriptable object and adjust it during development, but the actual current life should exist on a monobehaviour script, right?

#

assuming the maximum life can't be edited ingame or whatever

steady moat
urban lintel
#

right, so basically use it like a read-only file

steady moat
#

If you want to increase maxhealth because of a power up you do not modified the scriptable

urban lintel
#

that makes sense, thank you!

modern creek
#

When I put .png files into my project, how do I have them import as "Texture Type: Sprite (2D and UI)" by default? I can't seem to remember how I've done this in the past, and googling is .. problematic, I just keep getting pointed at the inspector window for a texture

modern creek
#

I have to do it in code? eep

steady moat
#

I believe there is a template you can have, but never looked into it. I might be wrong though and it is another engine

modern creek
#

I have other projects that I just drop png files into the project and they default to sprites.. I can't recall doing any code hooks for that

#

I may have setup those projects as 2d though

#

(ie - so unity did it for me)

steady moat
#

Try this

modern creek
#

K, created the preset, but unfortunately I still have to manually select the preset in order to apply those settings to the new textures

#

I thought there was a way to set up some sort of ... asset importer settings? but I can't seem to find it

#

found it

#

yeah, default behaviour "2d" makes new .pngs get created as sprites. 🎉

quiet flower
#

@steady moat can I ask you a question please

steady moat
#

Just ask, no need to ping me directly

urban lintel
#

@steady moat curious about that example you mentioned of a fireball, followed by 3 fireballs after one second. Since scriptableobjects themselves don't have access to update callbacks or coroutines as i understand, what approach would you use to create that delayed effect

steady moat
#

POCO or Monobehavior

quiet flower
steady moat
#

Its a unity feature

#

And a simple function call

quiet flower
#

Ohhh

quiet flower
# steady moat And a simple function call

I’m new to C# , started 6 days ago , I finished all the W3sschools lessons and I haven’t seen yet a block of code where the { is at the same line , how’s it possible ?

#

They’re always at the next line

#

To encounter the block of code

steady moat
#

and { after is only a style

#

which all c# use

urban lintel
# steady moat POCO or Monobehavior

as in pass a monobehaviour as an argument to the instantiate function and then use that to be able to schedule stuff?

  public override float Instantiate(GameObject shooter, Vector3 position, Vector3 direction)
        {
            shooter.GetComponent<Shooter>.StartCoroutine(CreateBulletAfterDelay(1f, position, direction));}          

or some more straightforward way. Also not sure how you'd do it with a POCO but either explanation would suffice!

quiet flower
#

Thank you

#

Didn’t know it was possible to choose it

steady moat
#

Most of the time, the delay come from an animation though. So coroutine would not really work well there.

#

Also, you need to think situation where you would interrupt your ability.

urban lintel
#

Those are all great tips, thank you once again

soft shard
north dove
#

Im slightly new to unity and C# and what im trying to do is calculate a bunch of variables inside my script 'ChainGenerator' and then make those variables public so i can use them inside another script 'GeneratingChains'. The ChainGenerator script creates two empty game objects to use as refrence points, and then does some math to calculate four x and y coordinates that i need. (I have a desmos project that shows what its calculating if you curious https://www.desmos.com/calculator/3ipsvqux5b)

Right now i have the script setup to calculate all the variables inside the first script and the second script is suppose to call those variables and put it inside of a splines knot coordinates. im getting errors like "Assets\Scripts\GeneratingChains.cs(19,38): error CS0428: Cannot convert method group 'Ipoint4' to non-delegate type 'float'. Did you intend to invoke the method?" And im also curious if there is a better way of doing what im trying to achive.

steady moat
#

If you want to store a function, use System.Func or System.Action

north dove
steady moat
#

Also, not exactly sure what is require to make a function be calleable in the variable definition.

north dove
steady moat
#
float Tangent1x = ChainGenerator.Upoint1(0f,0f,0f);
#

ChainGenerator.Upoint1 is not calculated, it is function.

#

You need to feed its parameter to have the value.

north dove
#

float ipoint1 = Ipoint1(Point1y, Size1, theta2); //Y position of first tangent, i1
this is in my first script

steady moat
#

I did not see the bottom part given that you did not use appropriate formatting.

#

But, if you want to access your value you need to expose them.

#

To be honest, this is really beginner level and it feels that you are missing core knownledge about programming in general.

storm wolf
steady moat
#

You should follow an appropriate tutorial

#
#

!learn

tawny elkBOT
#

:teacher: Unity Learn ↗

Over 750 hours of free live and on-demand learning content for all levels of experience!

rigid island
#

nothing beats good ol console apps knowledge / practice

modern creek
#

I'd like my 3d models to "face" the enemy while they aren't actively moving. I'm .. not exactly sure what that looks like though.

My game board is hex based, roughly 10 unit radius, and there's usually 5-10 units per team (just two teams). If units on team A always face one way, and units on team B always face another, it looks weird if they "get behind" each other. If the units face in the last direction they moved, that's also a little weird if they're moving away from the action.

I was thinking of calculating a team's "center" and having units of the other team face that point? But I am not sure how to math up the center of an irregular polygon easily.. I could just do a rectangle, maybe? But maybe that's not what I want, since 9 units on one side of the map and 1 on the other is gonna be .. strange.

#

Maybe some sort of weighted center..? Or just face the closest enemy..?

wintry crescent
#

or face in the last direction the unit moved

#

or yea, closest enemy

modern creek
#

the weighted center might actually be the easiest

wintry crescent
#

if you want the team center idea, you can use transform positions to calculate it, it's accurate enough

modern creek
#

add up all the vectors from the origin, divide the magnitude by the number of units..

wintry crescent
plush ridge
#

I have two scripts applied to the same game object, one inheriting from the other. Is there a way to fix having variables be duplicated across inherited classes? Am I using inheritance correctly? What would be the best alternative to maintain coupling? I'm only referencing _cardStats in the appearance class

wintry crescent
#

I'd say on a hex grid units should face towards one of the neighbouring hexes

#

not an arbitrary angle that might be pretty weird during late-game

#

where units are everywhere

modern creek
wintry crescent
plush ridge
modern creek
#

oh, and this is probably not using inheritance properly.. the card appearance probably should just figure out what card it's using (card appearance shouldn't inherit from card since the appearnce isn't a card)

wintry crescent
#

that's a good point

modern creek
#

appearance depends on the type of card, but isn't a type of card

wintry crescent
#

@plush ridge you should look up ScriptableObjects, your cards very likely need to be them

plush ridge
wintry crescent
modern creek
#

so .. you just want a reference to card in cardappearance:

public class Card
{
 public Rank Rank;
 public Suit Suit;
}

public class CardAppearance : MonoBehaviour
{
  private Card _card;
  [SerializeField] public Image Background;
  private void Awake()
  {
     if (_card.Suit == Spades) Background.sprite = CardSO.SpadesBackground;
     // etc
  }
}
plush ridge
modern creek
#

since a card appearance has to have a card (if I understand correctly) then you don't need a public setter, just have the card appearance look for the card component .. at some point, depending on your game

#

that way you don't need to remember to initialize the cardappearance with the card

#

you just... set the card and the cardappearance takes care of itself

#

(but don't do GetComponent in Update() - it's expensive/slow - do it when you need to, once)

wintry crescent
#

Now, am I correct in thinking that this would need a [System.Serializable] before declaration of Card, to appear properly in the inspector? I forget

wintry crescent
#

that too

modern creek
#

they should be MBs, I was just pseudocoding it

wintry crescent
#

I'm talking about System.Serializable for a custom struct to appear in inspector

#

or am I misremembering

#

w8 let me check really quickly

modern creek
#

tbh, not sure, i've never serialized a non-monobehaviour for the inspector

plush ridge
#

I'll set it up that way. Thanks!

wintry crescent
#

it doesn't show up without
[System.Serializable] before Card declaration

plush ridge
#

Did things slightly differently but, what yall think?

    private CardStats_SO _cardStats;

    private void Awake()
    {
        _cardStats = transform.GetComponent<Card>()._cardStats;

        UpdateCardRank();
        UpdateCardAppearance();
    }
#
 public class Card: MonoBehaviour
{
    [field: SerializeField] public CardStats_SO _cardStats { get; private set; }
modern creek
#

suppose I'll have to test it out in practice

#

obviously whenever a unit is moving or attacking, it'll face that direction

#

but when idling, the pink box seems like a good target

wintry crescent
#

not sure that's what you want long term

modern creek
#

but i mean, that's the same as them looking "at" each other

wintry crescent
#

when idling, last direction moved should be the look direction I think

modern creek
#

that's exactly what I want, i think

#

The problem is.. if you move a long range unit to the edge of the map then they'll have their back turned to everyone (until they next do something like attack towards the middle)

plush ridge
modern creek
#

5 enemies on one side of the map, the pink "target" square ends up right in the middle of them, which is .. pretty much perfect, I think?

#

oh actually there's a weird edge case heh...

#

if the player is in between some enemies and the target, they'll be right close to that group of 3 but face away from them

wintry crescent
modern creek
#

👂

wintry crescent
# modern creek 👂

each unit has a sphere around it, and you do that weighted position things on surrounding enemies close to the unit only
maybe based on its range? or only taking into account units it can attack, for ranged units?
and if no enemies are in range, face towards last moved position, or that general point for the whole army, that you calculated just now

#

and maybe when calculating for meele/short range units, make the weights of more distant units less important

#

so that it prioritises looking at units close by, but still takes the ones further away into consideration a bit

modern creek
#

Hm.. That seems like it's gonna be a bit complex/fiddly/error prone.. I think I can get something out of that, though, perhaps simpler

#

Like "heroes face right unless there's a unit within 8 hexes, then face the closest enemy"

wintry crescent
modern creek
#

facing closest enemy seems like it's always gonna be useful

#

I'm also not sure (yet) if there'll be stealth units

wintry crescent
#

you could also just leave it at what you have now, and fiddle with the direction algorithm when your game is developed further

modern creek
#

Yep, probably. I'm only a couple days in, but the timeline on this project is a bit tight. 😐

#

At least it came with some pretty cool 3d assets and animations

#

cute medic mouse don't take no shit 😛

wintry crescent
wintry crescent
wintry crescent
simple ridge
#

Hi everyone, sorry for the repost of a question but its been a few hours and no one has replied so I thought it would be fine to ask again.

I was wondering if their was a way to get the output of the gradient noise node in a shader, but from a script. To explain, I have a mesh on the floor in which its nodes are affected along the y by a gradient noise node. I would like to calculate foot IK positions for the player using this.

The floor does not have a mesh collider as this is being ran on a grid of several 100 tiles, so I am directly rendering the meshes using Graphics.DrawMesh(...), the gradient noise uses the world position of the vertex as an input so I should be able to get its output in the same way through script. But I cannot find if their is a c# version of this call that gives identical outputs.

leaden ice
simple ridge
#

Does the gradient noise built in to Unity.Mathmatics give the same output as the shadergraph noise function? And if not how would I go about porting it from the shader?

leaden ice
#

Does the gradient noise built in to Unity.Mathmatics give the same output as the shadergraph noise function?
Test it out and let us know.

And if not how would I go about porting it from the shader?
By copying the code over and translating it to C#

simple ridge
#

Mathf.Perlin does not match either Simple or Gradient Noise

#

Not entirly sure how to call the Mathmatics noise functinos but Ill give that a try next

#

pnoise and cnoise also do not match

dusky lake
# modern creek

Cinemachine has an inbuilt camera type for this, you just give it all objects to follow and set up when to ignore enemies (when they are too far) and it even zooms in and out for you if they get closer

hidden compass
#

using TargetGroups?

dusky lake
#

Yes

modern creek
dusky lake
#

Oh no then i missunderstood a bit, but i think you can also use a cinemachine targetgroup (without the camera) and use it for your purpose, as a look target

modern creek
#

Yeah, like I mentioned, that's all taken care of.. The user has control "normally" so they can move their VCam around however they want, but then we have a VCam for each unit and we blend cams into theirs whenever they do something interesting

#

Although one thing I hadn't thought of yet was when one unit attacks another.. Doing a targetgroup might be nice there to let cinemachine just show us a nice blend of both targets without having to manually fiddle it

modern creek
simple ridge
#

Well I've just tested to see if I get the same results using the code example for the LegacyMod version of Gradient Noise (Deterministic doesn't seem to exist in the docs https://docs.unity3d.com/Packages/com.unity.shadergraph@17.0/manual/Gradient-Noise-Node.html) and I'm still getting different results. My guess now is that either the maths is wrong from what I think its doing or that their is a difference in precision with Vectors functions and shader floats.

#
    private Vector2 NoiseDirection(Vector2 position)
    {
        position = Mod(position, 289);
        float x = (34 * position.x + 1) * position.x % 289 + position.y;
        x = (34 * x + 1) * x % 289;

        float temp = x / 41;
        float fractionalValue = temp - Mathf.Floor(temp);
        x = fractionalValue * 2 - 1;

        Vector2 vector = new Vector2(x - Mathf.Floor(x + 0.5f), Mathf.Abs(x) - 0.5f);
        vector.Normalize();

        return vector;
    }

    private float GradientNoise(Vector2 position, float scale) => GradientNoise(position * scale) + 0.5f;
    private float GradientNoise(Vector2 position)
    {
        Vector2 ip = new Vector2(Mathf.Floor(position.x), Mathf.Floor(position.y));
        Vector2 fp = new Vector2(position.x - Mathf.Floor(position.x), position.y - Mathf.Floor(position.y));
        float d00 = Vector2.Dot(NoiseDirection(ip), fp);
        float d01 = Vector2.Dot(NoiseDirection(ip + new Vector2(0, 1)), fp - new Vector2(0, 1));
        float d10 = Vector2.Dot(NoiseDirection(ip + new Vector2(1, 0)), fp - new Vector2(1, 0));
        float d11 = Vector2.Dot(NoiseDirection(ip + new Vector2(1, 1)), fp - new Vector2(1, 1));
        fp = fp * fp * fp * Add(fp * (Subtract(fp * 6, 15)), 10);
        return Mathf.Lerp(Mathf.Lerp(d00, d01, fp.y), Mathf.Lerp(d10, d11, fp.y), fp.x);
    }

    private Vector2 Add(Vector2 vector, int integer) => new Vector2(vector.x + integer, vector.y + integer);
    private Vector2 Subtract(Vector2 vector, int integer) => new Vector2(vector.x - integer, vector.y - integer);
    private Vector2 Mod(Vector2 vector, int integer) => new Vector2(vector.x % integer, vector.y % integer);
#

This is the C# code I am using

#

This is the comparison

#

This is the shader also, all it does is sample the perlin noise and add to the y position based on the output. (sample is based in world positions)

#

If anyone knows where this could be going wrong I would appreciate it

crude mortar
#

I don't know what's going wrong but those are my recommendations

glacial lion
#

currently pulling my hair out and failing miserably with any attempt i've made to create a pixel-perfect UI. ONLY the UI. if anyone has any tips or suggestions i'd appreciate them

#

(ignore the no cameras rendering that was just me messing with render textures)

leaden ice
glacial lion
#

oh that would be better thank you

empty elm
#

sometimes (rarely) my game crashes because there is a call to a function on a component on the same frame that it is being destroyed. Is the fix to check if gameobject != null in every public method on a script which may be destroyed at runtime?

rigid island
#

null check is a good start, but can be a bandaid

empty elm
rigid island
#

null check should be fine

empty elm
# rigid island null check should be fine

it seems to be random because it just happens to receive an incoming call on the same frame its destroyed. For example a playerController telling a weapon to fire on the same frame its destroyed. Could it be I'm not destroying things correctly and if I destroy both on the same frame it shouldn't be a problem?

#

null check definitely works though

spare island
#

that solution is also a bandaid though

#

some part of your code is working on an incorrect assumption that the object still exists

#

try attaching a debugger and look at the trace when you get a object is destroyed error

mild bridge
#

hey guys does anyone happen to know how I can shrink the "extrusion" of the tilemap so that the collision line matches the orange line?

#

i tried changing the extrusion variable in the collider but it doesnt show any difference for some reason, and ive been googling for an hour but its too vague and i cant find anything related

#

it works if I manually shrink edit a cell and then apply the manually made border, but theres a better automatic way right

#

wtf

#

i did nothing and it fixed itself

dusk apex
open basalt
#

will do, thanks

#

didn't notice the channel haha

rare turtle
#

I'm having trouble getting this to keep the clip I'm assigning to the AudioSource, can't figure out why.

The context is it's the pages of a storybook, and some of them have background music. The music all needs to sync up, so I need to have the pages with music playing at the same time but the volume down until the page is on-screen.
Because that would be a lot of audio clips, I de-duplicate based on asset path and create a list of pages for each audiosource.

When I do all of the below the log output is correct but the clip is blank in the inspector:

private List<BackgroundMusic> MusicList = new List<BackgroundMusic>();
private List<InstantiatedBackgroundMusic> Instantiated = new List<InstantiatedBackgroundMusic>();

public IEnumerator Init()
{
    for (int x = 0; x < MusicList.Count; x++)
    {
        bool foundInstantiated = false;
        for (int y = 0; y < Instantiated.Count; y++)
        {
            if (Instantiated[y].Clip == MusicList[x].Clip)
            {
                Instantiated[y].Pages.Add(MusicList[x].Page);
                foundInstantiated = true;
                Debug.Log("Music: Added another " + MusicList[x].Clip.name + " to Instantiated for page: " + MusicList[x].Page);
            }
        }
        if (!foundInstantiated)
        {
            InstantiatedBackgroundMusic ins = new InstantiatedBackgroundMusic();
            ins.Pages = new List<int>();
            ins.Pages.Add(MusicList[x].Page);
            ins.Source = gameObject.AddComponent<AudioSource>();
            ins.Source.loop = true;
            ins.Clip = MusicList[x].Clip;
            ins.Clip.LoadAudioData();
            Instantiated.Add(ins);
            Debug.Log("Music: Added " + MusicList[x].Clip.name + " to Instantiated for page: " + MusicList[x].Page);
            yield return null;
        }
    }
}```
#

here's those two data types

        public struct BackgroundMusic
        {
            public int Page;
            public string AssetPath;
            public AudioClip Clip;
        }   

        public struct InstantiatedBackgroundMusic
        {
            public List<int> Pages;
            public AudioClip Clip;
            public AudioSource Source;  
        }```
#

I'm loading the audio clip and storing it in BackgroundMusic, then passing that on to the data structure that holds the actual AudioSource. The debug output definitely has the name of the clip, but where I assign the clip above doesn't seem to be working

#

does anyone have any idea why my clip isn't making it to the AudioSource component? all of the other changes are, e.g. turning on looping

lean sail
knotty sun
#

wondering exactly the same thing

rare turtle
#

yeah that was it, thank you 🙂

open basalt
#

Hi all, just wondering, is it common to have some known bugs/errors popping up in your console that you can't get rid of, and you just live with it? Or am I doing something wrong?

open basalt
# cold parrot Can you be more specific?

I've posted on URP channel hoping for help, here's the error Im getting. From time to time I also get some GUI related error that I don't think is caused by my code?

#

Just wondering is it normal to have some random errors from time to time and you just clear it when it pops up haha

knotty sun
open basalt
#

Phew at least Im doing doing things TOO wrongly hahaha

knotty sun
#

which is why a lot of spurious GUI errors spring up

wary flame
#

would I be missing anything specific if I went from VS community to VS Code + unity extension?

knotty sun
mild bridge
#

ah kk

mild bridge
primal wind
#

Why is == default that much faster?

#

Not that it matters that much

#

but damn

late lion
#

== null and == default means the same thing in this context and gets compiled to the same thing. default is null for reference types like AudioSource.

primal wind
#

well f

flat marsh
#

Is it good to sometimes re-write a script if I am making a large systemic change?

wintry crescent
#

it's called refactoring

flat marsh
flat marsh
primal wind
#

That's my VSCode font

#

For some reason my brain can't accept it on any other IDE

#

So it's only in VSCode

jagged plume
#

Hey guys, not really a coding question but I mainly talk here so figured I would ask here as well

Don't you sometimes feel like games aren't fun anymore? like I would play 10h+ hours of league a day or hearthstone or whatever but now it does not really do it anymore?

Even the game I'm making is "pretty fun" but I don't "addicted" to it per se?

How do you guys deal with that (especially working in the game dev industry where well, we do it by passion most of the time)

primal wind
jagged plume
flat marsh
jagged plume
#

I mean I guess it is more of a lack of free time issue.

#

Also, it used to be that gaming was the default activity

#

not really true anymore

#

oh yeah it doesn't matter to me

#

that I don't play so much

#

my problem is more about not liking games as much as I used to

#

so that I'm less interested in making games (?)

#

and that sucks

flat marsh
jagged plume
#

not really (?)

flat marsh
jagged plume
#

yeah sure

#

But for instance

#

I used to be like "omg i'm going to remake monster hunter it's going to be the greatest thing ever"

#

but now I feel like "meh" about it(?)

#

although admittedly, I did code 12h a day for a month straight

#

at this point

#

maybe that has to do with that

flat marsh
# jagged plume I used to be like "omg i'm going to remake monster hunter it's going to be the g...

Thats fine man! You don't always have to have the same interests throughout your life. That's just the way it works! If you don't like playing games, don't force yourself to. If you dont like making games, do something else for a while. Life is all about change, and nothing ever stays the same. Sometimes ppl find something they really like and stick with it, but you shouldn't put pressure on yourself to like the same thing all the time.

flat marsh
jagged plume
#

But then, I don't really have spikes in other interests

#

so more like decrease of interest?

wintry crescent
#

burnout, maybe

jagged plume
#

without spike in others

wintry crescent
#

if you worked so much

flat marsh
wintry crescent
#

working 50% more than full time for a month straight

#

you need to pace yourself friend

#

or else you're gonna burn out and this will keep happening

#

chill out, slow down

jagged plume
#

isn't it necessary though to start your career?

wintry crescent
#

what, burnout? xd

#

no

jagged plume
#

no I mean

wintry crescent
#

I know what you mean

jagged plume
#

I have 1 month of "free time" left

wintry crescent
#

but you need to take care of your brain

jagged plume
#

yeah sure

wintry crescent
#

don't work this much, this is not sustainable

#

long-term

#

it'll burn you out, it already has to a degree

steady moat
jagged plume
#

yeah maybe I should take days off from time to others

#

I tend to skip the weekends too

wintry crescent
#

you actually need to do other stuff sometimes

steady moat
#

Usually, people works fulltime and do a game part time.

jagged plume
flat marsh
#

I also just wanna say (to balence out what I said above) it could just be burnout, not change of interest. This could be the problem with the gaming aswell

steady moat
wintry crescent
jagged plume
#

Well, I just really want to avoid the scenario where we just don't release the game because I did not program everything (?)

steady moat
#

It does not need to be done in 1 month ?

jagged plume
#

I mean kinda

steady moat
#

Then scope down.

flat marsh
jagged plume
#

Well, right now I only have like 1 boss left to program out of 4 levels (each level has an enemy with a specific mechanic and a boss fight)

jagged plume
#

It's like I'm "giving up" on the game in a sense

flat marsh
jagged plume
#

Like for instance, I had a boss fight where I wanted snow to rain down the screen and I never worked with ParticleSystem before

#

well that took a day

#

but I can't imagine the game without it

steady moat
jagged plume
#

so not much

flat marsh
#

Also, get feedback that is very important

jagged plume
#

One other thing that I realize when I thought I didn't like games anymore was that I didn't spend much time on level design on one level

#

which made the level tedious

#

that was another thing also I guess (now it's way better)

#

How do you get feedback typically?

flat marsh
jagged plume
#

okok

#

Well thank you a lot for your time guys

#

I'm going to take a nap, have a good one !

flat marsh
jagged plume
#

Oh

#

I just remembered something important

flat marsh
#

GL, cant wait to play it :)

jagged plume
#

A big part of my thought process was that playing video games feels like a "waste of time"

flat marsh
#

Btw, Can you @ me when the game is done? I wanna play it :)

jagged plume
#

whereas when I was a teen, it was more of a "potential career"

jagged plume
#

It's a metroidvania (?)

#

It's like my third small game

#

but it's bigger scoped than my previous ones

flat marsh
flat marsh
jagged plume
#

I mean I'm not sure if it's a metroidvania but it's more of a 2D side scroller fighting some monsters type of games and there are a few platforms but no death pits (?)

#

Does that qualify as a metroidvania?

flat marsh
#

yeah

#

I think it does

jagged plume
#

The second level is pretty fun

#

I want to spoil so much

#

ok just 1 thing

#

level 2, the small bears throw seeds on the rhythm of the music

#

like in new super mario bros for the koopa troopas (yes I did not want to scope down this because this gives soul to the game lol)

#

Anywhooo

#

Really going to take a nap now

#

I work night shifts at the moment

#

see you guys 🙂

upbeat crag
#

can I just ignore "Assertion failed on expression: 'SUCCEEDED(hr)'" error if it does not affect the game at all?

#

it appears every time I create new project or open old one

rigid island
#

yeah probably. How old is your unity version?

#

I used to get those in a very outdated version of unity

upbeat crag
#

I tried multiple versions, 2021.x 2022x and even unity 6

rigid island
#

ah well thats odd then

upbeat crag
#

Might be my GPU

rigid island
#

yes try updating your GPU drivers if you haven't done so

#

or do you have an onboard gpu maybe?

mighty void
#

Does anyone know what persistent malloc is? accumulates a lot of memory in the memory profiler

rigid island
#

would be nice if we had a #profiler type channel only dedicated to analytics and performance chats

upbeat crag
rigid island
# upbeat crag all my drivers are updated

not sure how true this is, found it on google

so my current solution to this is
menu: Edit > Project Settings > Player
on the inspector go oher setings
unpick auto API for windows then click + sign select direct3d12
drag it above direct3d11
apply

#

switching it to 12 idk seems like placebo but some peopel say it worked

upbeat crag
#

I'll try downloading even older version

static pollen
#

Hey guys, I have some errors in the PlayerControls script. So I was just adding a new action in my Input Action but suddenly there's so many errors and i don't know how to fix it.

#

ima send the code

#

the errors looks like this

leaden ice
static pollen
leaden ice
#

you probably generated it twice in differnt places

static pollen
#

okay, I'm gonna check if there's any duplicates

static pollen
static pollen
primal raptor
#

what is the problem here??

leaden ice
#

Basic NRE stuff

quaint gate
#

Is it possible to save serialized values into a single downcasted list, or do i have to save them seperately lists based on their types?

leaden ice
quaint gate
#

would I have to create a completely custom serializer for this? or would it be possible with unity's scriptable objects/yaml serialization?

leaden ice
#

Are you talking about Editor stuff?

quaint gate
#

yes

leaden ice
quaint gate
#

bleh, I was looking at that earlier, and it seemed like a pretty ugly approach

#

but i guess I could probably figure something out with some reflection here or something

drifting wedge
#

Hey, im trying to make my camera move when my mouse is close to the border but i have no idea whgat i mdoing and its not working

#

heres a quick sketch to demonstrate my intention

leaden ice
#

Oh I see. You're assigning the camera position to the delta instead of adding it

#

The last line should be += not =

drifting wedge
#

the camera teleported somewhere and i got this error

quaint gate
drifting wedge
#

what even si this

#

my numbers got letters in them sadok

somber nacelle
#

Scientific notation because your numbers are incredibly large

drifting wedge
#

il send a clip of whats going on rn if i play

quaint gate
#

1e1 = 10
1e-1 = -0.1
2e2 = 200
etc..

drifting wedge
#

i have no idea whats the problem

quaint gate
#

you're moving x when you should be moving z, and viceversa

#

that'

#

that's what it comes off as anyways, or is atleast one problem

#

also your Screen pos comparisons seem wrong, for most of them

leaden ice
leaden ice
drifting wedge
#

the camera always goes down, if i aim left nothing happens, if i aim up it goes left and if i aim top right it goes up

#

i feel like the pokemon that hurt itself in its confusion

quaint gate
drifting wedge
quaint gate
#

you should be comparing with
x < 0 + ScrollMargin
x > Screen.Width - ScrollMargin
y < 0 + ScrollMargin
y > Screen.Height - ScrollMargin

leaden ice
thorny sparrow
#

Hello all. The movement speed for players in my game is different on my pc from other pcs. What could be causing this? Here is my code for movement.

#

I'm not sure if the code is the problem because it was working not too long ago.

spring creek
#

Just completely remove it, and lower speed (because you will no longer be multiplying it by a tiny fraction)

#

Also, it looks like your !ide is not configured? Can't tell from just that

tawny elkBOT
spring creek
#

Well yeah, Input should not be white. Definitely not configured

thorny sparrow
#

okay thank you

#

ive never done that

spring creek
#

It will make a HUGE difference in coding. Error underlining (for more than just basics), suggested fixes, expanded autocomplete, code highlighting for ease of reading

thorny sparrow
#

that sounds great

kindred copper
#

When I set the RectTransform.MinAnchor and MaxAnchor (to a rectangle and not a point or line)
my gameobject scales to that size.... is there a way to make it NOT do that?
I even changed SizeDelta after setting min and max anchor and it still stretches my game object

kindred copper
#

is that a property in RectTransform im not seeing?

rigid island
#

oh sorry i see you did that with sizeDelta

#

that should not stretch your gameobject

kindred copper
#

I fixed it with
rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, length);
rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, width);

but now im getting a different issue 😮
ill need to grab a gif of it

#

the highlight is not anchoring correctly

rigid island
#

you have it stretch mode

#

also bad anchoring

kindred copper
#

im anchoring it to the grid of letters, is that not the way to go?

rigid island
#

anchor it dont put it in stretch mode

#

if you want the highlight, put that on stretch mode instead and put it as child of the "hightlight" rect transform

kindred copper
#

im sorry im not sure im understanding correctly 😦

which one is it suppose to be?

manic ether
#

Hey, Can anyone please help why am I getting such a camera behaviour. it starts alright, but as soon as I press the home button and the app goes to bg, then open it again it shows this flickering behaviour. Any potential insights why this is happening to my game?

kindred copper
#

sorry!

rigid island
#

what I would do is put the anchor first on top left corner, then achor that to the first letter in correct word

rigid island
#

this just shows us the symptom not the cause

kindred copper
manic ether
#

as it is trying to go inside a mesh renderer

#

no its not that

kindred copper
#

the blind guiding the blind

manic ether
#

the camera positioning is fine thats why the game runs fine at launch its just popping up when I reopen it after it has gone in background

wintry crescent
#

Or, even better, a phone emulator on your pc

manic ether
#

yeah it was reproducing, then i turned off the auto graphics api and it went away from that phone but in the device I discovered it ealier its still happening

manic ether
#

I found it somewhere as well. will give it a go as well

wintry crescent
manic ether
#

yeah, I ll see what the logcat says and will come back

#

cheers for the help so far, really appreaciate

odd void
#

So im learning a bit of DOTS at the moment and came across this line of code, i dont rly understand it, so i know entitys are the things in your world and i know what TranformUsageFlags do but i dont understand the AddComponent method? he is doing something there that i dont understand

#

So i know a few things about the AddComponent, i know that u need to tell it what entity to add the components to and what type of component but why does he gives a prefab with the component? is it to know wether its a cube or circle etc...?

oblique spoke
odd void
#

i'll ask in dots ig

odd void
#

this doesnt make sense, anyone knows more?

#

he is spawning components but a prefab isnt a component right?

rugged goblet
#

He's not passing the prefab to AddComponent, he's passing it to GetEntity to get the entity

odd void
#

if i understand correctly entitys are objects in your game right?

#

i dont understand what the prefab is meant to do? ye okay maybe tell the system what to spwn but what has that gotta do with AddComponent? why is that in the AddComponent?

rugged goblet
#

I think you're missing a lot of the fundamental concepts you need to be diving into DOTS

toxic vault
#

Any tips on how to create such a bar such that the width remains the same but the graduations can change?

I want to create one to show my current magazine size, so it would be anywhere from 2 segments (shotgun) to 30 segments (rifle).

I am open to purchasing one too from the asset store.

rigid island
#

otherwise you'd probably need a shader, or generate a mesh

toxic vault
#

I tried using horizontal layout component to see if I could just add/remove some elements. But it doesn't just work. As you can see the left and right elements don't exactly center. Definitely a lot of math involved

rigid island
#

gridlayout match the X cell size with the amount of segments within that space

#

just need to do some math with that, or assign them specific sizes manually and call it done lol

mossy snow
#

horizontal layout by itself should do the trick. Make sure your layout component controls child width

#

you need to have the layout force expand child width, or add a layout element to the children that makes them flexible

rigid island
#

tru i forget the option is there to control child size

surreal swan
#

Hey, has anyone tried to build webgl builds but not from player settings, but rather a custom solution. I am building some ci/di tooling and I am having issues with webgl local host.

#

this is the error that I get

#

Unable to parse Build/not-squidgame-webgl-build.framework.js.gz! This can happen if build compression was enabled but web server hosting the content was misconfigured to not serve the file with HTTP Response Header "Content-Encoding: gzip" present. Check browser Console and Devtools Network tab to debug.

#

This is the error that I get

#

from browser console

#

Failed to download file Build/not-squidgame-webgl-build.data.gz

warm badger
#

what would be the fastest(optimized) way to combine 5-6 array with around 15k elements in each array....the thing is the elements in the arrays are continuously changing after some frames...i am implementing grass rendering in a huge space, here i have to gather all the instance positions from 5-6 visible zones having ~15k positions per zone and send this huge combined array to a buffer in a compute shader....any help would be great...

simple void
#

array.CopyTo()?

#

If you wanna be completely overkill you can probably turn it into a native array and then make several parallel jobs each to copy a single array to a portion in the combined native array. You need to override saftey handles and stuff for that tho

warm badger
simple void
#

Sorry I take that back, you don’t need to mess with saftey stuff at all—I was thinking of a buffer

warm badger
#

i will try that job in a bit, i wanna see if there's any straightforward way to do this except job

cosmic rain
warm badger
simple void
#

Make sure your buffer is dynamic too then

simple void
#

That reminds me—compute buffers have a begin write method and end write. For max speed you should use those

#

They have less overhead

warm badger
warm badger
cosmic rain
#

As for the docs, you've gotta learn how to read them. What exactly do you not understand?

warm badger
simple void
#

Hey guys--I'm doing some questionable things in jobs, and I found something quite annoying. To use a callback I have to compile it into a Burst function pointer. I can't use a normal function pointer because Burst needs it to be Cdecl, and defining that as a function attribute is not available.

[BurstCompile]
static unsafe void OnEntityFound(UIntPtr nEntity, BirdEntity* bird)
{
  //Do something
}

context->sTree.QueryAsync(new STree.TreeNode.Bounds{
    Min = bird->GCoord - new int3(settings.flight.flightDistance),
    Max = bird->GCoord + new int3(settings.flight.flightDistance)
}, BurstCompiler.CompileFunctionPointer<Action<UIntPtr>>((entity) => OnEntityFound(entity, bird)));

All in all, I can do CompileFunctionPointer inside a job to create a usable callback, however inside callbacks I want to use some captured variables. As it's static I have to pass it through as an argument; the normal managed way to do this is to make a lambda which is not static and is able to capture your context variables--but I can't do that(hence why the code doesn't work) because the lambda is managed and is not BurstCompilable--is there a good way to get around this?

#

Because right now the best solution is to pass the callee function the context parameter just to have it call the callback with the context parameter.

cosmic rain
#

For starters !code

tawny elkBOT
simple void
#

Oh so that’s how ppl do that thx

placid star
#

hello I saw this one video about this guy making a game that deletes itself when you die, just curious how would you do it? I would like to try / understand how he did it, because from what I know, it is not possible to delete an application that is running, but you need it to be running in order to detect deaths and activate the script that deletes the game
https://www.youtube.com/watch?v=nIdO1Z8mD7Q 9:22

flat marsh
#

Its is done! I have finished me refactor of my movement script

#

to get it to work w/ rotation

toxic vault
#

@rigid island @mossy snow thank you so much!! Got it to work. I was trying to tile the blue lines instead of the red bars, and your idea worked perfectly!

mild bridge
#

ShadowCaster2DCreator.cs
https://pastebin.com/YzyXNUq0

S_PlayerTerraform.cs
https://pastebin.com/t534izqv

hi im having trouble figuring out this error that only pops up when i try to build, but not in play mode, i tried restarting unity, googling etc but theres no fix i can find, and theres no spellling mistakes either i think

wide terrace
mild bridge
#

ohh ill try messing with that
ye i didnt even see that lol (i got the script off a youtube guide)

#

thanks lol

flat marsh
#

Hey, what does {get; set} and {get; private set;) mean in unity?

flat marsh
#

ty

mild bridge
wide terrace
mild bridge
#

yeah i just realised after i sent that message haha

#

figuring out how to remove shadow caster's unity editor bracket without breaking the script rn

somber nacelle
#

i've only given it a cursory glance, but isn't the only part of the ShadowCaster2DCreator file that needs to be editor only the custom editor for it? just take that bit out and put it in its own file in a folder titled Editor

mild bridge
#

ohhh ill try that haha

#

yeah i frankensteined the run time in it was meant to be editor only

warm badger
#

The documentation. Look at the overloads

chrome trail
#

So is there any way I can have a rigidbody not transfer its velocity to something it collides with?

spring creek
#

You could stop the rigidbody before the collision by using raycasts or something. And setting velocity to zero BEFORE it even collides

chrome trail
chrome trail
#

Originally the plan was to simply have it be a trigger, but apparently triggers only work discretely

spring creek
#

What do you mean discretely?

#

They can be triggered as granularly as normal collisions

chrome trail
spring creek
#

Being a trigger won't actually affect it any differently in that regard

chrome trail
spring creek
chrome trail
spring creek
#

But if it is going fast enough, it will work with neither

#

Then spatial queries are required

thin hollow
#

I'm dumbfounded. Structs can't be null!!! But it's throwing me a null exception! WTF is going on?!


        public struct PolygonStruct
        {
           public List<Vector3> vertices;
           public List<Vector2> uv;
           public List<int> triangles;

            public PolygonStruct(bool needsVariable = true)
            {
                vertices = new();
                uv = new();
                triangles = new();
            }
            
            public static PolygonStruct operator +(PolygonStruct a, PolygonStruct b)
             {
                 var v = new List<Vector3>();
                 var t = new List<int>();
                 var u = new List<Vector2>();
                 
                 if(a.vertices.Count != 0)
                     v.AddRange(a.vertices);
                 if(a.triangles.Count != 0)
                     t.AddRange(a.triangles);
                 if(a.uv.Count != 0)
                     u.AddRange(a.uv);
                 
                 if(b.vertices.Count !=0)
                     v.AddRange(b.vertices);
                 
                 if(b.triangles.Count !=0)
                 {
                     int prevTCount = Mathf.Max(0, a.triangles.Count - 1);
                     foreach (int i in b.triangles)
                     {
                         t.Add(i + prevTCount);
                     }
                 }
                 if(b.uv.Count !=0)
                     u.AddRange(b.uv);
 
                 a.vertices = v;
                 a.triangles = t;
                 a.uv = u;
                 return a;
             }
        }         
knotty sun
#

At a guess you are not calling the correct constructor

cosmic rain
thin hollow
# cosmic rain Share the code/line that throws the error.

                PolygonStruct polies = new PolygonStruct();
                if (cap)
                {
                    PolygonStruct capPoly = MakePolygon(vert0, vert1, vert2, vert3,inv);
                    capPoly.uv = new()
                    {
                        new Vector2(0, 1),
                        new Vector2(1, 1),
                        new Vector2(0, 1),
                        new Vector2(1, 1)
                    };
                    polies+= capPoly;
                }
                polies+=  MakePoly(vert0,vert1,inv);
                polies+=  MakePoly(vert1,vert2,inv);
                polies+=  MakePoly(vert2,vert3,inv);
                polies+= MakePoly(vert3,vert1,inv);

Error's at polies+= capPoly; or the one += after that if cap is false.

knotty sun
#

there you go
PolygonStruct polies = new PolygonStruct();
your Lists are not initialized

cosmic rain
thin hollow
thin hollow
knotty sun
#

yes, sorry, i missed the default value

thin hollow
#

I'd made constructor parameterless, but it won't let me =\

knotty sun
#

tbh I see no reason why this is a struct in the first place

thin hollow
#

Ok so if I go

    PolygonStruct polies = new PolygonStruct(true);

instead of

    PolygonStruct polies = new PolygonStruct();

the error is gone now... what the hell. And I still can't make parameterless constructor, so is this how I'm supposed to initialize lists?

knotty sun
#

yes, you cannot overide the default parameterless constructor for structs only for classes

#

why did you make it a struct when all it contains are references?

thin hollow
knotty sun
#

of course, List is a class

thin hollow
#

They are of type Vectr3 and int, not objects or components... Aren't those variables?

knotty sun
#

irrelevant

thin hollow
#

TBH it was a simple array before, I changed them to lists in trying to figure out what causes the exception

knotty sun
#

but Array is also a class so no difference

#

if you are trying to get cloning on the cheap it ain't gonna work

thin hollow
#

I'm not doing cloning, I'm trying to simplyfy procedural mesh generation so I won't have to manually punch in vertexes and triangles and shit

paper heart
#

Is there way to set Halo component's Size from code?
I tried this but it doesnt set the value (it only works for reading the current value)
halo = new SerializedObject(GetComponent("Halo"));
halo.FindProperty("m_Size").floatValue = haloSize;

thin hollow
#

I bfigured that passing the data needed to make a polygon around as a single struct variable would be simpler than every function requiring three variables

knotty sun
static pollen
#

here's the code

knotty sun
#

!code

tawny elkBOT
static pollen
#

ok lemme try that

#

that's the code