#archived-code-general

1 messages · Page 353 of 1

onyx cypress
#

it ended

rigid island
#

Vector3.Distance(transform.position, target)

#

put this in a variable and print it

onyx cypress
#

ok

rigid island
#

well yeah save manager has all the saveables

storm wolf
#

They have to implement it right

rigid island
#

yes thats why only ISaveable objects have their own SaveData class for exaample

#

they need to follow the strict rules enforced by interface

onyx cypress
#

it 2.55

storm wolf
#

Ok so they do know about it then

rigid island
onyx cypress
#

yea

rigid island
spring creek
onyx cypress
#

no i put it on the ground

spring creek
#

It is at y value 257, while your player is at 254
It says right there in the logs

onyx cypress
#

thats not my player

#

thats the enemy

storm wolf
#

Only thing im not understanding is how it becomes ISaveable for the save manager i get that it sends itself to the save manager into like a list of isaveable or whatever

spring creek
#

That is 3 meters above the enemy
Oh, 2.5 about. So exactly the distance you logged of course

rigid island
onyx cypress
#

ok let me see than i changed all the numbers of player, enemy and chekcpoints to 256.5

spring creek
#

That is about 2 meters above the enemy

#

The enemy is at 254.44

#

That is what you need to have all the waypoints at if the terrain is flat

steady moat
#

Just ignore the Y instead of positioning them at the same height ?

spring creek
#

Very good point

onyx cypress
#

now its not moving to even one checkpoint

spring creek
#

Do what simferoce said

#

Just check the distance to a vector using the x and z of the target, and ignore the y (plug in the enemies own y value)

onyx cypress
#

ohok

#

sorry

#

like this?

spring creek
#

I am not seeing any difference. It is still checking distance between transform.position and target

#

new Vector3(target.x, transform.position.y, target.z)

onyx cypress
#

bro i dont get anything

#

im just gonna scrap this project

#

to be honest

onyx cypress
storm wolf
spring creek
onyx cypress
spring creek
onyx cypress
#

ok

spring creek
#

You could also make a variable and set that when you assign a new waypoint as target, so you don't have to create a new vector every frame
But then it would be the y position of the enemy at that point in time and not update

rigid island
#

how much data are you saving from how many different data types

storm wolf
#

I have one created already and it is pretty simple I was just wondering about the interface approach as its probably better than mine

#

Currently i just put everything in a PlayerData class and serialize and save that

rigid island
#

interface adds a whole other layer of complexities

storm wolf
#

Why use it then

#

And I am just curious how that approach works

#

I was thinking about the event option that seems like a good approach too

rigid island
#

idk there isn't a specific way to do it thats why i'm wondering what you're trying to accomplish

#

I have interface but had to use a Dictionary with it but that now adds complexities of GUID and ofc not being able to serialize it with native serializer

storm wolf
rigid island
#

my specific usecase was doing items you can store inside Crates / Inventory / Backpacks

#

so yeah I had to make Unique IDs for each item, because once you pick them up and save, You dont want the game obviously spawning more on Load

#

this involved doing custom dictionary serialization and it was a pain

storm wolf
#

I have done that before but not with an interface

rigid island
#

you dont technically need the interface but it surely helps

#

I have a video i watched a few years ago on this

#

lemme find it

storm wolf
#

But if you have a save method with the interface wouldnt you need to serialize in there each time

#

Yes pls🙏

rigid island
# storm wolf Yes pls🙏

https://youtu.be/cwSKPIvWvpM?list=PL-hj540P5Q1hLK7NS5fTSNYoNJpPWSL24
was either this one or the few videos before/after

🚨 Wishlist Revolocity on Steam! https://store.steampowered.com/app/2762050/Revolocity/ 🚨 This series will teach you how to create a minecraft style inventory system in Unity 3D - this is includes stackable items, with a max stack size and the ability to split and combine stacks, and delete them from your inventory.

I show off everything we will...

▶ Play video
storm wolf
#

Awesome ill watch in a bit

unique thunder
#

Can you add an ASP.NET API into a Unity solution that gets triggered to run when the Unity project runs? So you don't have to host a API but rather inside the same solution

rigid island
#

you should not have an API on the client anyway

cunning burrow
#

this is straight up bullying, unity isn't serializing my vector2 correctly...

#

wait holdon, is it like {"x": 0, "y": 1} or smth

#

you gotta be joking me if that is the case

rigid island
#

why would it not be

cunning burrow
#

it seemed logical it would parse a tuple as a vector

rigid island
#

which tuple ? they're different types completely

#

vector can only contain float/int
tuple can have multiple datatypes

#
List<string> omg = new();
(List<string> omg, Vector3 position, bool, float) crazyTuple = (omg,transform.position, true , 23.3f);```
cunning burrow
#

well anyway it was an easy fix server-side

rigid island
cunning burrow
#

the thing lol

#

anywaysss

rigid island
#

nice

#

{} is the vector2 object

#

x , y are the keys

cunning burrow
#

I just had to change how my server represents positions

#

I mean my server already does a lot of translations to allow easy serialization in unity

rigid island
#

my server just saves regular C# classes/struct.
In unity i already convert them to that
eg Vector3 goes into a custom Position struct etc.

#

I use a class library to do it though so Unity project/objects doesnt have to know any of it

cunning burrow
#

I have custom classes but stuff like the game definitions data has a lot of complex dictionaries which unity doesn't parse so I have a custom serializable dictionary type for that and I have to make my server convert these for unity

rigid island
#

oh okay. I lazied out and went for Json.net

cunning burrow
#

umm a debug tecnique but how do I check what keeps resetting my object's position (except idk, going through each script)

rigid island
cunning burrow
#

nah it's the animator for damn sake

#

but like, I only want it to control z

#

I might just move it out of the animator tbh

#

but then I need to wait for animations and shit to finish to change the stupid z

rigid island
#

I'm not good with animator so I'm not 100% on that.

void basalt
#

will using assembly definitions noticeably reduce assembly reload times in larger projects?

spring creek
rigid island
#

not really a code question

karmic herald
#

idk where else id ask sorry 😞

rigid island
karmic herald
#

ah

#

i can move it there then

late lion
void basalt
late lion
void basalt
#

ah okay

rigid island
#

domain reload can be disabled btw

late lion
#

But I mostly use assembly definition files for organization. It means you can separate code and define clear dependencies between them.

#

For entering playmode, yes, but not for code recompiles.

rigid island
#

truth

chilly surge
#

Domain reload time is far far higher than compile time.

late lion
chilly surge
#

Not sure about ECS, but I think Burst compilation is async.

#

Either way though, shaving a second or two off compile time dwarfs in comparison to domain reload taking tens of seconds or even up to minutes.

subtle spoke
#

How can I make sure ENABLE_WINMD_SUPPORT is on?

#

I've done everything that the Unity docs told me to (IL2CPP, .NET Framework in settings) but my code refuses to believe I have WINMD support (I am on a windows computer)

subtle spoke
#

No, I just want to use UWP APIs in Unity

#

specifically Bluetooth LE

late lion
#

I don't know much about Windows Runtime or UWP, but from a quick search, it appears you cannot access WinRT APIs from a regular C# app, for example, without changing the runtime target to a specific .NET version which is WinRT compatible.

visual flare
#

getting UnassignedReferenceException on this:
rigidBody?.AddForceAtPosition(direction, hitPoint, ForceMode.Impulse);
rigid null should skip AddForce, right?
can someone explain what that exception is and how to get around it without expanding the ?. into an if ()

lean sail
#

this isnt using unitys null check on it

visual flare
#

except for that one...

lean sail
# visual flare except for that one...

unless the rb is being destroyed, im not really sure why the error appears. As far as i know, unitys null check also checks if the object is destroyed

#

also couldnt that above line just be simplified to
targetObject = tmpTarget.gameObject if it isnt already a game object?

visual flare
twin egret
#

is there a reliable way to call OnDestroy() for a ScriptableObject? i'm having an issue where something that i thought would be destroyed isn't getting destroyed

cold parrot
#

if you destroy them in the editor (in edit mode) you should handle cleanup with an explicit call to a cleanup method from the outside.

twin egret
# cold parrot You’re not supposed to destroy them dynamically

oh im not destroying them dynamically. to be clear, what i want is for OnDestroy() to be called when i exit play mode. i have the following code to destroy a sprite that i create using Sprite.Create(...)

private void OnDestroy()
{
    Debug.Log("Destroy called on a theme!");
    if (cachedSprite) Destroy(cachedSprite);
}
cold parrot
#

they do not have a play mode lifecycle

twin egret
#

i see. so if i want to store temporary data related to a ScriptableObject, that needs to be done in another way?

cold parrot
#

Not necessarily, you just have to call that cleanup function some other way

#

You can hook into the editor application play mode changed event for example (I forget what it’s called exactly)

cold parrot
#

The typical (often recommended) use case for SOs however is to treat them as containers for immutable data, not even holding any internal non-primitive state

digital falcon
#

I'm using the gitignore file but I'm unsure how do I have it ignore the ArtifactDB file in Libary? I put it in the right place with the proper format to boot:

twin egret
#

okay, so i'll have to change my solution then. i wanted to cache some data on the scriptable object but that'll have to move somewhere else

digital falcon
#

Anything else I've missed?

cold parrot
#

maybe

#

files already tracked by git will not be ignored

digital falcon
#

Oh

digital falcon
#

Cus I did what you asked, same problem like usual.

cold parrot
digital falcon
#

Ok!

cold parrot
#

Alternatively close unity, delete the library folder, commit, then reopen Unity

digital falcon
cold parrot
#

if you have committed the library folder once (by accident) your git repository is however full or useless changes, if you cannot reset the repository to a state before that commit, it’s best to recreate it

digital falcon
#

Deleted the Library Folder.

#

Git still thinks I have the Library. I think I gotta clear the history.

twin egret
#

are you willing to lose your commit history

digital falcon
#

No

twin egret
#

because you should probably just delete the .git folder and reinit the repo at this point

digital falcon
#

Ok

twin egret
#

wait

#

you DON'T want to lose your commit history?

digital falcon
#

Is that a bad idea if I loose it?

#

Mostly as I'm worried it'll delete the main project as well.

#

Its my first time uploading it to git so nothing much has changed yet.

twin egret
#

you won't lose your files if you do, but if you have a history of commits, you would lose that

digital falcon
lean sail
#

you could always just clone the project, then do whatever you need like try remaking the repo

digital falcon
#

Ok

lean sail
#

tho do you really have anything in the git history? sounds like you just started using it

digital falcon
#

Nope

#

Just started.

#

Like legit just started a week ago.

twin egret
#

just go to the folder where your project is (Assets, ProjectSettings, etc.), turn on hidden files, and delete the .git folder

#

you can reinitialize the repo from there

digital falcon
#

Any notes with the last two?

twin egret
#

you already have a git ignore

#

unless you're open sourcing your project, it's fine to leave license as none

#

i haven't touched a git gui in forever so idk if this is going to commit everything automatically

#

also another question: is using a scriptableobject as the key in a dictionary a good idea or nah

cold parrot
nimble cairn
#

Is there any reason why my FPS portal-like physics based puzzle platformer SHOULD NOT have variable jump height?

The player builds bridges to solve puzzles and get to the end of a level/chamber. The bridge building is the core mechanic. I like the idea of letting the player the decide what type of jump they want to preform for the situation at hand. Keep in mind HOW you traverse the level/movement is a huge part of the game!

All this and I'm still not 100% certain.
If I did add variable jump height how would you teach and reinforce this mechanic to the player with an invisible tutorial?

languid mantle
#

Hello, i have a question.
Is there a way to capture the desktop audio? i need to capture current desktop audio and send it via WebRTC for my screen sharing system?

digital falcon
#

Deleted the Library, well:

#

😿

twin egret
#

just open the scene you had open last

#

deleting Library deletes your current editor state

digital falcon
#

Done

#

How do I commit?

#

New Library, new .git folder.

twin egret
#

whats the history tab got

spring creek
digital falcon
twin egret
#

okay then yeah commit when you make changes

nimble cairn
digital falcon
twin egret
digital falcon
#

I changed a bit of the coding to try and have Github commit but it doesn't respond.

#

Lemme try something

cosmic rain
digital falcon
digital falcon
#

Bonus when after I booted it up on Unity:

#

So its all good, thanks everyone!

cosmic rain
opaque forge
#

Hi all, I'm generating meshes procedurally, I want to apply a different texture which would represent a pavewalk on the red parts I drew in the image. I have to cut the mesh, but I'm wondering what is the best way to do this, do I have to create 2 different meshes?

gloomy path
#

Heya, got a question.
Anyone has an idea how to edit the autogenerated Scripts?
Namely the Entities C# scripts, which don't appear in the Data/Resources folder

knotty sun
glossy isle
#

hi

#

how can i add message box

#

in my game

knotty sun
glossy isle
knotty sun
#

yes

gloomy path
knotty sun
gloomy path
#

I'm looking to change the baker template

knotty sun
gloomy path
#

Any idea where that might be?

knotty sun
gloomy path
#

Thank you

knotty sun
gloomy path
#

Got it

onyx cypress
zealous bridge
#

I want to write modules which are engine independent. For example, I would make image filters. They would use Image abstract class I would make. It would have setpixel and getpixel abstract methods. I would use adapter pattern yo make unity, godot, monogame APIs fit into my hierarchy. Each Implementation of my abstract image class would have constructor injected API texture class with pixel read write access. UnityImage will have constructor injected UnityEngine.Texture2D texture; and will inherit my abstract class and I would implement setpixel, getpixel by saying texture.getpixel(x, y). Similar approach would be used to make GodotImage and MonogameImage implementations of my abstract class. This is common practice in industry to use adapter pattern to make different APIs fit into same abstraction and be able to swap implementations.

I just wonder what is best way to write modules (nuget, dll or something else) which is supported by all engines. I initially wanted to use nuget since it enables versioning (different versions of project use different version of module/library). I really don't want to use git submodules for versioning because they are extremely confusing when trying to merge, resolve merge conflict, update. I read somewhere that godot doesn't support nuget but they probably support adding dll (or so files since I am on ubuntu) files to some directory. Do all engines/frameworks support .dll (.so)? Is it easy to setup? What is best way of versioning those dynamic libraries? Do they have good performance? I would typically make git repo for that classlib with .net standard 2.0/2.1 so unity doesnt complain and make a bunch of versions/commits of that library. But that may cause dll hell where different dll files have same name and I don't know which version they are. How should I go with thid dll modular approach?

stable osprey
#

all engines that support C# code should support DLL yeah

#

and ones that don't support C# code probably still support DLLs in one way or another (untested, but DLLs are a universal programming thing, so I have to assume it's fully working universally)

#

yes DLLs have good performance. Nuget is best for distribution, others are suboptimal

#

DLL hell is easy to get in yeah. Plus it can be annoying for devs that want to use and potentially extend them, so maybe you should consider packing your whole engine in a single DLL

zealous bridge
#

Should I make some bash script which reads first row of commit message and appends it to dll name? "ImageFilters - added basic filters for rotating.dll" would give me ability to know which version is which since different dll versions would have different names. In csproj of that classlib used to make ImageFilters.dll, I would add line which automatically executes bash script for dll renaming.

thin aurora
#

You can also support C and C++ DLLs in your application by using the extern keyword and loading them into your application

#

The thing you should worry about is compatibility between .NET versions in your DLL. Generally you want to target a .NET Standard version if you want others to use your library

zealous bridge
#

If all engines somehow supported nuget, what would you suggest as easiest solution regarding performance, versioning and ease of use?

thin aurora
#

For example, Unity supports the latest .NET standard version

#

But often people use some .NET version like .NET 8 and Unity does not support that

#

So instead you should also compile for .NET standard if you want to support Unity. You can specify multiple target versions in your .csproj file

#

And I believe Godot supports .NET 8 just fine but I don't remember for sure

thin aurora
#

Nuget is not a thing you support

#

Nuget is a general package manager for .NET, but you don't use it with Unity because Unity only allows very specific versions and generally they would need to implement some feature for Unity

#

That's why Unity doesn't use Nuget but instead has its own package manager

#

You can "support" nuget but there is no guarantee the dll you download from it works

#

So anyway

dusky lake
thin aurora
#

If you plan on making "general modules" for anything, you should target specific versions so that anybody can use it. .NET Standard, maybe much older versions. You can use processor directives to compile code specific to a version if older versions are not supported.

#

And considering it's not related to Unity you upload these to Nuget

#

As for performance, this makes no sense. Nuget has nothing to do with performance. It's up to you to write good code that has good performance

zealous bridge
#

What about using static linking? Is it possible in C#? Is it batter way to deal with dependency version hell?

stable osprey
#

what's static linking now?

#

no if you wanna get away from it pack everything on a single DLL

#

as for versioning it's git territory -- nothing to do with anything else really

#

u might wanna keep a constantly up-to-date public const string version = "0.001beta"; which gets printed upon first initialization if you want.

#

otherwise organize your branches with release, develop, 0.1, 0.2 etc to keep track of releases -- and only push to develop, only cherry-pick to release from develop, and duplicate branches to version branches before making the DLL

stable osprey
zealous bridge
#

Ok C# cannot use static libs I didn't know. I have watched some yt recently and found out that godot supports nuget and that there is some github NugetForUnity repo which enables nuget window to visually add nuget packages. That github is someone's add hoc solution which may or may not work every time but at least there is some way to have nuget in unity

stable osprey
#

github has option for release pages now that potentially include changelogs & binaries, but nothing beats Nuget -- since it automatically tells you which are up-to-date

#

yeah there's an Unity asset that allows nuget downloads but what Fused said above stands

glossy isle
magic vine
#

Hey there, Im currently having issues with the rigidbody.velocity.magnitude function
im trying to detect, wether or not the Rigidbody (attached to a different GameObject) is moving with a speed != 0
However, this change is only detected, when the Rigidbody comes in contact with another Rigidbody (ie. comes in contact with an enemy)

After some fiddling around, I noticed that this weird behaviour only occurs, when all 3 axes of the Rigidbody´s rotation are frozen, if at least one of the axes is not frozen, the code works normally
Could anyone help me figure out how I can make this work with all 3 axes frozen?

Code:

using System.Collections.Generic;
using UnityEngine;

public class animationStateControlle : MonoBehaviour
{
    Animator animator;
    [SerializeField] Rigidbody rb;
    
    // Start is called before the first frame update
    void Start()
    {
        animator = GetComponent<Animator>();
    }

    // Update is called once per frame
    void Update()
    {
        if (rb.velocity.magnitude > 0)
        {
            print("Change detected");
        }
    }
}```
leaden ice
#

If you're not moving it via physics then the Rigidbody isn't going to have a velocity

spiral palm
#

how would i get the number of lines in a text file?

knotty sun
leaden ice
final valve
#

i assign the scrollbar right, but when i put it into the prefabs it dis assigns, so then theres no scrollbar assigned? why is this

leaden ice
final valve
leaden ice
#

(assets in general can't reference objects in scenes)

leaden ice
final valve
spiral palm
knotty sun
leaden ice
#

You don't need to do anything with the hierarchy

leaden ice
magic vine
magic vine
#

but thx for the help mate!

rigid island
#

how should someone know what it is on YOUR specific project UnityChanThink
Profile and find out.

#

also this seems unrelated to unity

modest mural
#

that's why it's in the code general section

#

shrug

rigid island
#

your post is not related to that

modest mural
#

my bad, it's not clear that this scripting section is only for asking help with unity as nothing implied this was unity specific scripting questions in the read me channel. removed, sorry for trying to share

spring creek
modest mural
# spring creek The entire server is for unity only. They don't really specify that for the chan...

Yeah, that's why I shared a details about a setup I use to make coding my Unity games easier and I put it in this channel because it is titled as code-general which I understood to be related to writing code and using Unity. What @rigid island said is that this is only for asking help questions, not sharing resources.

Thanks for joining in on the unnecessary clarification though about what the Unity discord is meant for.

spring creek
modest mural
#

clearly

dawn nebula
#

I have a plane here and a perspective camera at a downward 45 degree angle. I want to right click + drag and be able to move the camera along the plane. Any tips?

leaden ice
dawn nebula
# leaden ice Plane.Raycast to get the world space positions of the mouse. Then it's just a ma...

Ya I did something similar and upon right click the camera jerks.

    private Vector3 _origin;
    private Vector3 _difference;

    private Plane plane = new Plane(Vector3.up, Vector3.zero);

    private void LateUpdate()
    {
        if (Input.GetMouseButtonDown(1))
        {
            var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            plane.Raycast(ray, out var distance);
            _origin = ray.origin + (ray.direction * distance);
        }
        if (Input.GetMouseButton(1))
        {
            var newRay = Camera.main.ScreenPointToRay(Input.mousePosition);

            plane.Raycast(newRay, out var newRayDistance);

            _difference = newRay.origin + (newRay.direction * newRayDistance);
            mainCameraFocus.transform.position = _origin - _difference;
        }
    }
rigid island
#

obligatory cinemachine 😮

dawn nebula
#

I am

leaden ice
#

cinejmachine doens't really help in any way for this

#

but yea

rigid island
#

well the follow to a new target would be smoothed thats all

#

but yea lol

dawn nebula
#

I'm moving a target for Cinemachine to smoothly track as opposed to moving the camera itself.

leaden ice
#

Or rather, you're interpreting the results incorrectly

dawn nebula
#

I thought it returned the distance to interception?

leaden ice
#
_origin = ray.origin + (ray.direction * distance);```
This is wrong, it should be:
```cs
_origin = ray.GetPoint(distance);```
#

oh wait that's the same actually

#

sorry

dawn nebula
#

_>

#

All good. That's a handy helper method at least.

leaden ice
#

I misread

#
mainCameraFocus.transform.position = _origin - _difference;```
#

I don't think this is right

#

let me check my code for this. I've done this exact thing before

dawn nebula
#

This is what I'm experiencing.

#

The jerks are a single right click.

dawn nebula
leaden ice
#

Does this work @dawn nebula ? I couldn't find my code but I tried to rewrite it:

Vector3 _origin;
Vector3 _cameraOrigin;

private void LateUpdate()
{
    if (Input.GetMouseButtonDown(1))
    {
        var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        plane.Raycast(ray, out var distance);
        _origin = ray.GetPoint(distance);
        _cameraOrigin = mainCameraFocus.transform.position;
    }

    if (Input.GetMouseButton(1))
    {
        var newRay = Camera.main.ScreenPointToRay(Input.mousePosition);

        plane.Raycast(newRay, out var newRayDistance);
        Vector3 newMousePos = newRay.GetPoint(newRayDistance);

        Vector3 diff = _origin - newMousePos;
        mainCameraFocus.transform.position = _cameraOrigin + diff;
    }
}```
final valve
#

in unity how do i detect the object that hit something? all i can find it the object that was hit, i wanna tp the plr or the object that hit the other object to somewhere

leaden ice
final valve
leaden ice
final valve
#

ohh

leaden ice
#

this object is just this.gameObject

final valve
#

whats the $ for?

lean sail
#

Itd be quite useless if it only told u what the current object was

leaden ice
final valve
leaden ice
final valve
#

a tp script

leaden ice
#

then the player is collision.gameObject

#

or you might want collision.collider or collision.rigidbody or collision.transform

#

depending on your needs

final valve
#

so then how would i detect if the plr hit the part to then do smth

leaden ice
#

check if the object is a player

#

then do the thing

#

That might mean checking its tag, or checking if it has a specific component on it

#

for example:

if (collision.gameObject.TryGetComponent(out Player p)) {
  p.Teleport(someLocation);
}```
final valve
#

so where do i now put the function? how do i connect it so it fires

leaden ice
#

In OnCollisionEnter of course..?

final valve
#

it isnt doing anythig tho

leaden ice
#

without any if statements

#

to make sure it's even running

#

If it's not running at all, you didn't set up the objects correctly for OnCollisionEnter

final valve
leaden ice
#

show their inspectors

final valve
#

ignore the plr transform its not needed

leaden ice
#

and the player?

final valve
#

its multiplr so i cant just have 1 player

leaden ice
#

Can you show the inspector for the player too?

final valve
#

its why i wanna detect

leaden ice
final valve
leaden ice
#

I just want to see the inspector for the player object that you expect to collide with this teleporter

leaden ice
#

I just want to see its inspector please

final valve
leaden ice
#

CharacterController does not trigger OnCollisionEnter

final valve
#

oh

leaden ice
#

and I think that code can only be on the CC side

final valve
#

oh

knotty sun
lean sail
spring creek
final valve
leaden ice
final valve
#

rigid bodys

leaden ice
#

Where did you get that idea?

final valve
#

bc it assigns it Rigidbody body = hit.collider.attachedRigidbody;

leaden ice
#

It's checking if the other thing has a Rigidbody

#

It's also completely not important

#

It's just example code

final valve
#

oh

#

so how do i put it into my terms

spring creek
astral sky
#

figured

final valve
#

like that?

rigid island
rigid island
#

what does it say

final valve
#

the same as what i put

rigid island
final valve
#

yes

#

is hit, what has been hit/touched?

final valve
rigid island
#

what?..

#

hit is just a variable name

final valve
#

what for

rigid island
#

this is basic c# stuff

rigid island
#

for the datatype it returns

final valve
#

well im confused bc u sent an atricle of what is what but hit isnt there so idk what hit is gonna be used for

rigid island
#

do you know what Method parameters are?

restive ridge
#

I made a Debug.Log check for the brake/reverse input. If the car is stationary or moving backwards, and i hold brake, the car moves backwards and the message keeps getting sent as long as i am holding brake, as expected. but if the car is moving forward and i hold brake, the message is only sent once and the car doesn't brake.
https://gist.github.com/Winter-r/447c521d359129f2586cc6ae923b2dbd

rigid island
tawny elkBOT
spring creek
weak spruce
leaden ice
weak spruce
#

here is code

final valve
lean sail
leaden ice
#
GameObject Sheep = Instantiate(sheep, SpawnPosition, transform.rotation = RandomRotation);```
#

transform.rotation = RandomRotation < this rotates the object the script is attached to

#

i.e. the spawn area

#

To spawn an object with a random rotation you would just do:

GameObject Sheep = Instantiate(sheep, SpawnPosition, RandomRotation);```
You have the extra `transform.rotation = ` in there which is causing your problem
stable osprey
#

Why not just MonoBehaviour.Update?

#
public abstract class MBPool<T> where T : MonoBehaviour, IPoolEntity  {
    protected Queue<T> pool = new Queue<T>();
    protected Transform poolParent;
    
    public virtual void Initialize(int maxAmount, T prefab) {
        poolParent = new GameObject($"{typeof(T).Name} pool").transform;

        for (int i = 0; i < maxAmount; i++) {
            var newObj = UnityEngine.Object.Instantiate(prefab, poolParent);

            newObj.OnSpawn += () => OnSpawn(newObj);
            newObj.OnDespawn += () => OnDespawn(newObj);

            OnEnqueue(newObj, i);
            pool.Enqueue(newObj);
        }
    }

    public virtual T GetNew() {
        if (pool.Count == 0) { return null; }
        var obj = pool.Dequeue();
        obj.OnSpawn?.Invoke();
        return obj;
    }

    protected virtual void OnEnqueue(T poolObj, int i) => poolObj.gameObject.SetActive(false);
    protected virtual void OnSpawn(T poolObj) => poolObj.gameObject.SetActive(true);
    protected virtual void OnDespawn(T poolObj) {
        poolObj.gameObject.SetActive(false);
        pool.Enqueue(poolObj);
    }
}
#

this doesn't handle automatically collecting despawned objects, but sounds like better architecture than having a manager for despawning objects

#

(simple I mean the usage 😛 the contents may not be that simple lol)

#

np!

lean sail
#

Though regardless if you want to automatically return objects to the pool then ideally you have some timer, either on the pooled object or the pool itself keeps track of them all in a separate list

#

You can skip a lot of the beginning since it's very specific to unitys networking for game objects (NGO)

spring creek
# glossy isle bro nobody answer me

I mean, what are you expecting as an answer? The question is so vague.
Make a panel and child a text component and... write some text? I dunno because you do not describe what you actually want at all.
Go to the #📲┃ui-ux channel and write a WAAAAAAAAAAAAAAAAAAAAYY more descriptive question.
With details
And images if necessary

stable osprey
#

this thanks came with an engagement proposal 😆

glossy isle
#

i want to add it in my game

#

but idk

#

just this

rigid island
stable osprey
#

@glossy isle 😂 dude you're really funny!

rigid island
# glossy isle i want to add it in my game

Here's a little tutorial I put together on how to create a text window that displays messages. In this video I show you how to create a script that runs the text window, chat input and messages sent to the text window. This is my first unity tutorial so if there is something that I could clarify or perhaps improve on in the future, feel free to ...

▶ Play video
glossy isle
glossy isle
stable osprey
#

I mean -- what you posted is full-fledged multiplayer chatbox, it's unlikely to get it done simply by following a tutorial 😅

#

also the way you posted it was funny as heck lol

spring creek
rigid island
glossy isle
spring creek
#

What?

glossy isle
spring creek
#

what does "I can get response" mean?

glossy isle
spring creek
rigid island
#

where do you think we get our answers from most of the time?

glossy isle
#

searching

#

google . youtube

rigid island
#

and the docs/manual

#

not that difficult to learn how to use them properly

glossy isle
#

aha

#

ok

#

thanks

#

can i come t yr dm and ask something ?

rigid island
#

I don't do DMs sorry

fallen lantern
#

Hello everyone,I have been having a problem with a small project im working which is the top,bottom,right and left faces of this randomly generated cubes show up with distorted textures

I have been tinkering with it and I think I have probably made a mistake on how I make the triangles for the faces of how I give/assign the UVs
Here is some screenshots with how it looks in the editor and the code behind it

Could it be any of this 2?

jovial valley
#

For my game, I want to create an upgrade system in which I can change certain things about a tower and those changes will apply when i call Upgrade on a Monobehaviour, like how you can have overrides on a prefab variant. However, I dont want to reinstantiate the gameobject, is there a way to make it so that it will store the overrides of a prefab variant (or a functionally equivalent system), and allow me to change that based on changes when I upgrade?

next quiver
#

I am working on a vampire survivors like game. In the game, if you have a pistol in inventory, you start automatically shooting. If you have two pistols in the inventory, there should be two instances of these auto shots but I was not sure how to best implement this. Creating an actual new instance of the class wont work since its monobehavior.

lean sail
lean sail
next quiver
#

okay yea addcomponent would be a way to go about it, thanks. How would you instantiate the bullets without monobehavior?

lean sail
#

Instantiate is just a method, you dont have to call it from a monobehaviour

tender gull
#

another problem is rendering to texture

potent anchor
#

Starting a new project and marked my camera and player as DontDestroyOnLoad. In my second scene I have another player and camera object I use for building and testing, but when I play through the first scene and load the second, I was expecting to have duplicates (those in the second scene + the ones marked DND from the first scene)

#

But that's not happening. It looks like the DND gameobjects from the first scene are overwriting the gameObjects that I placed in the second scene

#

That's ...neat, but unexpected?

#

Does it work automatically that way now?

lean sail
potent anchor
#

so weird. thanks for the confirmation. I'll go find out where it's de-duping

lean sail
#

I'm gonna make a wild guess and say its in the same area you use DDOL probably because you made the player a singleton and destroy all other instances

potent anchor
#

yes

#

long day. Thanks

#

You should sell remote omniscient debugging services

cosmic rain
#

It's something you learn here after some time of helping people.

#

We can also see your project with a third eye and read your thoughts.

lean sail
#

👻 the error is on line 15

potent anchor
#

That's a really legit guess given that singleton code is generally up top

minor stream
#

hey so i need help making a game, im struggling to put my ideas into it and need help, i know it kinda seems a little jumpy but i could really use the help.

#

i have taken classes on coding with unity before but need some help with it

cosmic rain
#

What's the actual question?

spring creek
minor stream
#

yeah, im just trying to put it into words

#

So basically, i want a system where if the player hits the enemy every time the enemy and the player go up in the air, To put it like this
One hit would just launch the enemy backwords
Two hits would send you and the enemy upwords a little bit and then if their is no other button press, you both fall back down
Three hits would launch both of you up and the last hit would knock the eneny back

spring creek
#

And what have you found online when you looked?

minor stream
#

kind of

#

lemme finish the text cause i accedently pressed enter early before i could finish what i was writing

#

lemme make a diagram

cosmic rain
minor stream
#

ive tried something like that

#
    private float distance;
    EnemyBehavior enemyBehavior;
    PlayerBehavior playerBehavior;
    EnemyAI enemyAI;
    public bool CanAttack;
    public bool DoubleAttack;
    private float LastClickTime;
    private const float DOUBLE_CLICK_TIME = .5f;
    void Start()
    {
        enemyBehavior = GameObject.FindGameObjectWithTag("Enemy").GetComponent<EnemyBehavior>();
        playerBehavior = GameObject.FindGameObjectWithTag("Player").GetComponent<PlayerBehavior>();
        enemyAI = GameObject.FindGameObjectWithTag("Enemy").GetComponent<EnemyAI>();
    }

    // Update is called once per frame
    void Update()
    {
        distance = Vector2.Distance(transform.position, Enemy.transform.position);
        if (distance <= 2)
        {
            CanAttack = true;
            if (Input.GetKeyDown(KeyCode.P))
            {
                if (PlatformGameManager._playerStamina.Stamina > 0)
                {
                    Debug.Log("Hit");
                    float timeSinceLastClick = Time.time - LastClickTime;

                    if (timeSinceLastClick <= DOUBLE_CLICK_TIME)
                    {

                        enemyAI.EnemyLaunchUp();
                        playerBehavior.PlayerLaunchUp();
                        enemyBehavior.EnemyTakeDmg(10);
                        playerBehavior.PlayerUseStamina(20);
                        DoubleAttack = true;
                    }
                    else
                    {
                        enemyAI.LaunchBack();
                        enemyBehavior.EnemyTakeDmg(5);
                        playerBehavior.PlayerUseStamina(10);
                        DoubleAttack = false;
                    }
                    LastClickTime = Time.time;

                }
            }

        }
        else
        {
            CanAttack = false;
        }
    } ```
blissful minnow
#

Which unity extension do I use in visual studio code?

tawny elkBOT
#
Visual Studio Code guide

If your IDE is not underlining errors in red or autocompleting code,
please configure it using the link below:

https://on.unity.com/vscode

minor stream
cosmic rain
minor stream
#

yes

cosmic rain
#

And? What did you discover?

minor stream
#

nothing

#

idk if i debugged right though

#

hold up

cosmic rain
#

Debugging means finding the issue cause and potential fixes via various techniques, like logging, drawing debug info/gizmos, or stepping through the code with a debugger. If you didn't discover anything, then your debugging failed.

#

Or rather, you never completed the debugging.

cosmic rain
# digital falcon How so?

It might cause issues during the build due to file access rights.
Ideally, put your project close to the disk root.

spring creek
#

So something like C:/UnityProjects is always preferable

digital falcon
#

Ah

jovial valley
#

can I make it so that a certain ScriptableObject only appears when I rightclick a prefab, just like a prefab variant?

#

using UnityEngine;

[CreateAssetMenu(fileName = "New UpgradeAsset", menuName = "???")]
public class UpgradeAsset : ScriptableObject
{
public GameObject originalPrefab;
}

#

smth like that

#

and it stores the prefab I created it from in originalPrefab?

soft shard
# jovial valley can I make it so that a certain ScriptableObject only appears when I rightclick ...

Im not sure ive seen this use case before, ScriptableObjects are files that are stored in your project, a prefab can reference that file, though I dont see how restricting creating it to a specific prefab would help if it would create a file in your project that anything can reference anyway? Through the attribute alone there is no way to do that, AFAIK it would likely involve a custom editor window or editor script - what might be the end goal of such a system? Why is this specific scriptable object unique to only one specific prefab in your project?

jovial valley
#

Well basicaslly

#

i want to create a very flexible upgrade system for prefabs

#

where I can change like everything about them, similair to how a prefab variant works. Right now, ive been trying to figure out how to hijack prefab variants for htis use case, but I was exploring the possibility of creating my own custom asset to work better.

soft shard
# jovial valley where I can change like everything about them, similair to how a prefab variant ...

Ah I see, there are likely other ways but one that comes to mind is possibly using generics, interfaces and inheritance to create "variants" with different logic and public variables, it could help to maybe plot out a set of what your variants could look like, what needs to change between them and how you intend to use or reference those changes, for example you could use a serialization library like Newtonsoft JSON and use text files instead of ScriptableObjects, depending on the depth of your system and how you intend to use them, both would have a different process for actually populating and making copies of your data though (although a ScriptableObject is also basically a fancy YAML text file that Unity serializes)

hot sorrel
#

hey if there are multiple references to the same instance of a custom non-unityobject on multiple classes that needs to be serialized is it a better idea to use serializefield or serializereference

spark vigil
#

Depends on the behavior you want. Is it important that they all reference exactly the same object?

#

If not, it doesn't really matter. SerializeReference may give you smaller data size I suppose

hot sorrel
#

yeah i expect to have 6+ different things referencing the same object

hard estuary
little meadow
#

I feel like the answer is SctiptableObject... or it doesn't matter... but oh well 🤷‍♂️

frigid turtle
#

Hello there guys! How to disable creation and uploading symbols.zip for Android build?

#

i did some research and found almost nothing about it

little meadow
#

It's in the build settings, no? There's a dropdown for them symbols

frigid turtle
#

yeah, i forgot to say my build starts through command line or something like this, and idk where the person who responsible for this solution

little meadow
#

is it an automatic build thing? it still probably uses whatever settings the project is with, so you can change from the same place and push 🤷‍♂️

#

There is EditorUserBuildSettings.androidCreateSymbols if you need to change it from code, I guess 🤷‍♂️

oblique spoke
#

There's probably a script in the Unity project being invoked by the build script. Check to make sure if it's overriding any settings

frigid turtle
frigid turtle
#

anyway thanks

edgy stump
#

How I can build game with script?

#

I mean, when I run.exe file, and in the game I press the button called "Build", it should be build game for windows

frigid turtle
edgy stump
#

Like this?

frigid turtle
#

yeah, doesn't it work?)

edgy stump
#

Here's other script:

using UnityEngine.UI;

public class BuildButton : MonoBehaviour
{
    public Button buildButton;

    void Start()
    {
        buildButton.onClick.AddListener(OnBuildButtonClicked);
    }

    void OnBuildButtonClicked()
    {
        #if UNITY_EDITOR
        BuildScript.BuildGame();
        #endif
    }
}
frigid turtle
#

oh right, it's only from editor so i think you cant run it in the game)

edgy stump
#

Yeah, I'm dumbass

frigid turtle
little meadow
#

obviously the build script should be in editor folder or entirely #if UNITY_EDITOR'd

edgy stump
little meadow
#

I mean... it's the editor that is building the game... where else would you want it?

frigid turtle
edgy stump
little meadow
#

you can't... but also am curoious for the use-case

frigid turtle
#

you may run like bash script or kinda from your game

oblique spoke
frigid turtle
#

@edgy stump

#

i think it should be like this

edgy stump
frigid turtle
#

yep

#

so you need to get access to this file and run it

edgy stump
#

I have to run it through a script?

edgy stump
#

thank you

frigid turtle
#

np

edgy stump
#

But I still have one more little question

oblique spoke
#

You can start the process from C# too

frigid turtle
#

i hope it works)

edgy stump
#

What if this game is on Android?

frigid turtle
#

oh it may be significantly harder to run if not even imposible)

oblique spoke
frigid turtle
#

actually imposible))) it's android, you dont have an editor on a device

little meadow
#

did we discuss the use-case?

#

this seems super weird to me... I'd think there's a better way of doing whatever, unless it's really super specific

frigid turtle
#

no, still very interesting))

lean sail
lean sail
# edgy stump Game building system

i really dont feel like playing 20 questions to get more information. It sounds like you're trying to make an app which can create games? You simply arent gonna be building a game from an android app.

tribal jay
#

hey, when i want to restart my game in singleplayer i just call SceneManager load scene and it restart the game, but i unity netcode when i want to do the same thing it doesnt restart the game when using Networkmanager.SceneManager.Load. What am i doint wrong?

lean sail
neon pine
#

How can I make a randomly wandering animal on the map in Unity?

little meadow
#

pick random point - go to it, when you reach it - restart the process

knotty sun
simple ridge
#

Hi All, I was wondering if anyone knew the best way to render meshes with multiple materials using Graphics.DrawMesh and if it is more performant to use DrawMesh or RenderMesh?

torpid glade
#

guys help me in this one i try to build app then this error comes up

knotty sun
bright relic
#
                if (validVectors.Count > 0)
                {
                    Vector3 averageDirection = Vector3.zero;

                    foreach (var vector in validVectors)
                    {
                        averageDirection += vector;
                    }

                    averageDirection /= validVectors.Count;
                    vectorField[current] = averageDirection.normalized;
                }```

right now im calculating the vector of my resistance field by taking the avarage. but it should point into the avarage of the lowest resistances. how could i make the lower resistances weigh more than the higher ones?
steady moat
# bright relic ```// Calculate the average direction if (validVectors.Count > 0...

How about something like that ?

float average = 0;
var elementWeightNormalizeds = elements.normalizeWeight();
foreach element in elementWeightNormalizeds 
  average += element.value * element.weight

[(0.5,0.7), (3, 2), (1, 1.5)]
float weightSum = 0.5 + 3 + 1 = 4.5
[(0.11,0.7), (0.66, 2), (0.22, 1.5)]

average = 0.11 * 0.7 + 0.66 * 2 + 0.22 * 1.5 = 1.727
#

A more performant way would be:

average = (0.5 / 4.5) * 0.7 + (3 / 4.5) * 2 + (1 / 4.5) * 1.5 = 1.727
static matrix
#

fellas I think I mistyped something

bright relic
rigid island
#

classes are just blueprints to objects

static matrix
#

gamerunner is the static instance of this class (GameRunner)
I mistyped "this" and it corrected to "ThaiBuddhistCalendar" which I thought was hilarious

glossy trench
#

If I'm to understand this correctly, if I'd like to use Scriptable Objects to save data for my character creator.. would it be best if the data while it's 'hot/live' is kept as a JSON in memory - then once the character is finished, create a new instance of the SO we'd based this JSON off of initially, populate it with data from this JSON, then save this new SO asset to the disk?

Sorry if I'm wording it vaguely lmao, just want to know if this is how it should be done

steady moat
#

ScriptableObject is not made to save data from runtime.

glossy trench
#

Okay, so it's more for when you have static data you'd like to 'plug in'

cold parrot
glossy trench
#

Would using it for a game save then, where I'm instantiating a new SO asset, not be recommended?

vivid wave
#

Yo

cold parrot
#

no, not recommended

vivid wave
#

Can I make a ticket?

cold parrot
vivid wave
#

Okay

cold parrot
#

you can even put a reference to that game state which you want to save/load into your SO if you really want that.

#

but that would be more or less the same as a global static variable, and that generally is not a great thing to have.

cold parrot
#

regadless many simple games use a global game state object successfully. Its up to you how to make that accessible and how to mitigate the issues it brings. Piping it through an SO is one of the options,

glossy trench
#

So I could use the structure of that SO and have my game saves as actual JSONs without a hitch in the future as my project gets increasingly complex? (lmao open-ended question)

cold parrot
#

its irrelevant that its an SO

#

you have a global state object and everything in your game will be coupled to that object's structure

glossy trench
#

Trying to understand this. A class would serve the exact same purpose and structure, right?

cold parrot
#

if you expect a complex data model and worry about maintainability, you could inject objects only with a small portion of that gamestate (through an interface), effectively reducing the surface area of the coupling

cold parrot
#

a SO is just an instance of a class that is automatically created on application start and gets its public (serializable) fields filled with static configuration you defined when editing the game in the unity editor.

glossy trench
#

OH

#

Coughs in not going through the unity tutorials

cold parrot
#

an SO solves the problem of "where do i put my static configuration" for unity projects

#

you could also look at them as custom asset types

glossy trench
#

So, having the options as an SO itself would be pointless since we're going to be messing with it at runtime anyways?

#

Braining: If I'm to have a bunch of SOs in a folder, let's say it's uhh.. Graphics Presets. We're never going to change those at runtime, and we can reference them easily like they're just a convenient data container. Like any other static object. However I choose to store my actually runtime-modifiable settings data, it's all good for me to reference those SO assets?

I hope I understand now what they're actually for. I was using them like this before, but got caught up in figuring out how to save a bunch of characters. I'm going to check out custom assets now based on the advice.

uneven slate
#

Unity documentation is shit. what do I use to raycast from a position & direction in worldspace, to hit a canvas, in worldspace.

leaden ice
#

performing a raycast yourself is not necessarily the right approach

#

Physics raycast (probably what you were looking at) is only for physics colliders, not UI.

static matrix
uneven slate
#

I'm trying to raycast from a position and direction in worldspace, to see if that ray hits a canvas within a set distance.

I'm aware physics raycast doesn't hit it. I'm trying to figure out what raycast does hit it.

leaden ice
#

what's the actual goal

#

what are you trying to achieve.

#

There's a better way to do it probably

uneven slate
#

To know if the ray is hitting a canvas. Internal logic. XR shit.

static matrix
leaden ice
#

but also - generally you would just use the event system directly

#

if you're trying to do UI interaction

uneven slate
#

I'm not trying to do interaction, I'm trying to see if an arbitrary point in space, with an arbitrary direction, and an aribtrary distance, would cast a ray that hits a UI element, whether that UI element is on screen or not does not matter in the least. it's not for interaction. it is just for seeing if a point would hit a canvas.

turbid silo
#

I do not know if this is here that I have to ask some questions for help but here an "issue" I met by attempting curiosity test.

It's a little question that may take only a minute to answer but I can't find the answer whether by using Unity Docs, GPT or VS Intellisence built-in feature :

// Enable the input actions
playerInputActions.Test.Enable();

// Subscribe to the different phases of the action
playerInputActions.Test.Press.started += OnPress;
playerInputActions.Test.Press.performed += OnPress;
playerInputActions.Test.Press.canceled += OnPress;

I have this code, is it possible to compact all of those subscription to my action phases ? Like is there a keyword allowing me to trigger OnPress() whenever it's started, performed or canceled ? All of that without having to have three subscription so.

leaden ice
uneven slate
#

Graphic Raycaster lives on the canvas, as opposed to an arbitrary point, right?

leaden ice
#

Then use it as such:

SubscribeAll(playerInputActions.Test.Press, Onpress);```
leaden ice
#

and needs to have the event camera assigned

turbid silo
leaden ice
#

I'm not really sure I understand the question.

turbid silo
leaden ice
uneven slate
#

So there's seriously no way without putting a camera on the arbitrary points I want to check for UI? Unless the camera doesn't actually do anything, the implication is that it wouldn't work if the camera was for example pointing in a completely unrelated direction, so I can't just reuse the main one.

knotty sun
turbid silo
leaden ice
#

it means "a function that takes a InputAction.CallbackContext parameter and returns void"

turbid silo
leaden ice
#

yes

#

exactly

#

see how your function has that parameter?

turbid silo
leaden ice
#

that's what the delegate type is enforcing

turbid silo
#

Oh

knotty sun
unreal notch
#

Hey is anyone here familiar with OSCQuery for VRC?
I am writing a very simple program in C#, the program is already writtena and works, I've gotten as far as building an OSCQueryService that is recognized by VRC, but I am having trouble understanding the limited documentation and examples available, and I am stuck on the last step of... how do I send my data to VRC?

https://pastebin.com/ncx22VmW
Here is my code, I feel like I'm just one step away from completing this but I cannot figure it out... any help would be greatly appreciated!

and heres a link to the library I am using
https://github.com/vrchat-community/vrc-oscquery-lib/tree/main

turbid silo
#

So basically, it want to check if the function I'm calling have indeed this paramater ?

leaden ice
leaden ice
#

See what happens if you try a function without that parameter

#

it will give you an error

turbid silo
#

I'ma try

smoky atlas
#

I'm trying to implement leaderboards for android and I don't understand why i'm having so many issues.
Only a few times have I seen the play services banner show at the top of the screen with my user and then it stopped showing up.
I saw the leaderboard ui once, but I can no longer get it to show.

Log output

IntegrationHelper --------------- Google Play Services -------------- IntegrationHelper Google Play Services - VERIFIED Play Services: User is authenticated = False Play Services: Trying to authenticate the user Play Services: User authenticated = True Play Services: Trying to show leaderboard, user authenticated = True

#

`public class GooglePlayService : IGameCenter
{
public void Initialize()
{
PlayGamesPlatform.DebugLogEnabled = true;
AuthenticateUser();
}

private void AuthenticateUser()
{
    if (!IsAuthenticated())
    {
        Debug.Log("Play Services: Trying to authenticate the user");
        // PlayGamesPlatform.Activate(); # calling this makes the call below fail
        Social.localUser.Authenticate(OnAuthenticateUserCallback);
    }
}

private void OnAuthenticateUserCallback(bool isSuccess)
{
    Debug.Log($"Play Services: User authenticated = {isSuccess}");
}

public void ReportScore(int score, string leaderboardId)
{
    if (IsAuthenticated())
    {
        Social.ReportScore(score, leaderboardId, OnScorePostedCallback);
    }
    else
    {
        Debug.Log("Play Services: Cannot report score, user not authenticated");
    }
}

private void OnScorePostedCallback(bool isSuccess)
{
    if (isSuccess)
    {
        Debug.Log("Play Services: Successfully reported score");
    }
    else
    {
        Debug.Log("Play Services: Failed to report score");
    }
}

public void ShowLeaderboard(string leaderboardId)
{
    Debug.Log($"Play Services: Trying to show leaderboard, user authenticated = {Social.localUser.authenticated}");
    Social.ShowLeaderboardUI();
}

public bool IsAuthenticated()
{
    var authenticated = Social.localUser.authenticated;
    Debug.Log($"Play Services: User is authenticated = {authenticated}");
    return authenticated;
}

}`

fleet gorge
#

doesnt show any errors helpful to us

dark shoal
#

leaves no errors

naive swallow
dark shoal
#

I have; same results

naive swallow
flat bane
#

I have 2 enemies with dynamic body types in Rigidbody. When i walk to them i can just move them backwards. I found a solution by making them static when in range. Is there a better way to do this?

#

!code

tawny elkBOT
flat bane
#
        {
            Vector2 direction = (player.position - transform.position).normalized;
            movement = direction;
            isAttacking = false;
            rb.bodyType = RigidbodyType2D.Dynamic;
        }
        else
        {
            movement = Vector2.zero;
            rb.bodyType = RigidbodyType2D.Static;
        }  ```
knotty sun
#

post your question in the correct channel

weary coral
#

whoops im new

knotty sun
weary coral
#

ive got it now

zinc parrot
#

so in my unity asset/plugin I distribute to others I have an xml file that holds material information
The users who download this plugin can add to this xml file
But when I distribute an update and they import the updated package, if they forget to disable the importing of the material xml from the package, all their changes get overwritten and deleted
is there a way around this to disable it automitically if the file already exists?

knotty sun
zinc parrot
#

when the updated package gets imported, itll overwrite it seemingly no matter what resources folder it is in

knotty sun
#

not if you move the file and delete the original .meta file

zinc parrot
#

but it needs to be loaded through resources.load

#

so it needs to be in a resources folder, which unity will automatically create a .meta for

knotty sun
#

you misunderstand me
original in Resources
after import move file to Resources/Loaded
delete original .meta file
unity will create a new .meta for the moved file
then you can check if the Resources/Loaded file exists or not and not overwrite it if it does

#

include an asset postprocessor script in your package

zinc parrot
#

oh wait no

#

ok I think I understand

knotty sun
#

no, it will still import the original into Resources but will allow you to decide what to do with it

zinc parrot
#

ahhh sweet

smoky atlas
frosty surge
#

I have an egg falling from a rotated plane, the plane gameobject is nested inside a gameobject which i rotate the plane with, i am trying to spawn some rocks from a level generator gameobject, the problem i couldnt figure out how to make the spawn position relative to the rotation of the plane.

Any help will be appreciated.

leaden ice
#

then convert to world space with Vector3 worldSpacePosition = myPlane.transform.TransformPoint(randomLocalPoint);

compact spire
#

So I've been using the ol' just ask a question in chatGPT to help me with some of my coding, Are there any setups with good integration with Unity/Rider that people are using these days? I don't mind if it's got a fee associated.

spiral bridge
#

Is there a way to get the Avatar that the AnimationClip was imported with? Editor only way is okay.

I'm trying to make a tool to assign animations to component properties quicker.

spring creek
#

!ide

tawny elkBOT
compact spire
#

@spring creek Sorry, I guess my question was a bit unclear, I am using Rider with Unity, I'm referring to AI tools/workflows in that context.

spring creek
#

Honestly, I try to avoid ai since it is 9/10 times garbage, so I don't know

spring creek
spiral bridge
spring creek
#

Yeah, I was thinking copilot would be the only one. Glad to hear confirmation about support

compact spire
#

I was hoping to try something like Cody, but it's not available for Rider

#

Rider also has AI assistant, which is Jetbrains own

#

I'm sure there are other extensions as well

spiral bridge
compact spire
#

Maybe those are my only 2 options

spring creek
spiral bridge
#

I'll try there too, thanks

compact spire
#

From what I read copilot is better than AI Assistant

#

but I also found Cody does have a plugin for Rider

#

So I will give that a shot

twin egret
#

is unitask really as good as it seems to be?

brave hazel
#

my state doesn t change, and this appears in animation. If i press manual on the bool variable work but automatic don t. I don t un
derstand why.
Imagine

dark shoal
serene wolf
#

Hello everyone, I'm looking to achieve some kind of limb removal in a Kenshi like way, do anyone has any insight on propers way to achieve this?

zealous bridge
#

I have untracked changes and I do git reset --hard HEAD but those untracked changes are still there. Internet says that is probably has to do something with line endings and git automatically changing them on checkout or commit. I attached my .gitattributes. Is it incorrect? it doesn't contain "crlf" anywhere. I have empty unity project and don't know when is .gitattributes necessary so I add it from the beginning. Is it wrong practice?

thorn crag
#

if i set time.timeScale to 0, and then tried to recolor an object, would the object be able to be recolored?

spring creek
#

Were you perhaps using deltaTime to smoothly change it? DeltaTime will of course be 0 when timeScale is 0

thorn crag
spring creek
thorn crag
spring creek
#

Ok. Update is the reason it is not working

#

Callbacks like OnClick will still be called 🤷‍♂️

#

Could call it BEFORE setting timeScale to 0 too, if possible

thorn crag
#

but there is other code in update that is being called like normal, and it will still force the value 255, 255, 255 even if i change it in the inspector

spring creek
#

Hmm. Then you have other code setting the value somewhere

#

You should probably just show the code of course

#

Oh, are you using Color or Color32 in code?

thorn crag
#

Color

spring creek
#

Then it is only values of 0 to 1

#

If you set it to 1,1,1,1 or anything greater that is the same as 255,255,255,255 in the editor

thorn crag
#

i changed it to Color32 and it works now!

#

thank you :)

raven basalt
#

I tried importing an animation from blender to unity, but the scaling of the animation doesn't work, even though the rotation and the location of the animation works. Anyone know how to fix this?

little meadow
spring creek
#

I've been away from unity so long I keep forgetting things

little meadow
#

FixedUpdate won't be called as it does require some time passing in the simulation

subtle spoke
#

After some more investigation, this is what I have happening:

UNITY_EDITOR_WIN and UNITY_STANDALONE_WIN both work in scripts written in unity. it determines it to be true
Neither work in a C# file I made in Visual Studio and imported into Unity via DLL. In fact, when I removed those IF statements, it gives me an error saying that it is "Unable to resolve reference 'Windows.Foundation.UniversalApiContract'"

This is probably an issue on VS's end. How can I resolve this error and make Bluetooth LE able to work in Unity?

somber nacelle
#

Neither work in a C# file I made in Visual Studio and imported into Unity via DLL
this is to be expected. those preprocessor directives determine what gets compiled, if those symbols are not defined, then the code they encompass will not be compiled at all into the DLL

subtle spoke
wide terrace
#

Just to elaborate a bit further, they're interpreted immediately prior to compilation. They don't exist at the time of compilation nor in build artifacts/output.

subtle spoke
somber nacelle
#

do you have the relevant DLLs in your project?

subtle spoke
#

Yes, they are in my VS project
Not in Unity, because i'm not sure which are the relevant DLLs (I'm trying to use the Windows.Devices.Bluetooth and Windows.Devices.Enumeration) DLLs

#

@somber nacelle

somber nacelle
#

i am referring to your unity project. do you have the DLLs you are trying to use in your unity project, because if not then naturally you won't be able to use them in your unity project

chilly surge
#

#if are preprocessor directives, they take effect during compilation, and so they have already taken effect when you compile your code to the .dll.

subtle spoke
#

I'm trying to use the Windows.Devices.Bluetooth and Windows.Devices.Enumeration

somber nacelle
#

well you'll need to figure out what DLLs you need and add them to your project

subtle spoke
#

It says "unable to resolve reference windows"

#

let me check how to solve that

#

yeah there aren't really any ways to fix that online

#

yeah after adding system.windows it still insists that its unable to resolve reference windows

chilly surge
#

Adding to where, Unity?

subtle spoke
#

yeah

#

Just also tried to use the windows api

#

it says

#

The type or namespace name Devices does not exist in the namespace Windows

cosmic rain
subtle spoke
late lion
#

It's not possible to access in a regular Windows Standalone build.

subtle spoke
#

like if I click the normal unity run button, can it access the functions?

#

like Windows APi

late lion
#

You have to build. The editor doesn't run under the Windows Runtime.

subtle spoke
#

oh

broken light
#

has unity put the navmesh obstacle code up on github? i need to modify it to support custom polygon shapes

iron vortex
#

If I have a public abstract class that inherits from MonoBehavior, how might I pass a reference to this class to a subclass that inherits from the abstract class?

leaden ice
#

What's the use case?

#

What are you trying to accomplish?

#

note also that you generally don't deal with references to classes. You are generally dealing with references to instances of a class.

iron vortex
#

I have a MonoBehavior method that I need to call but can only pull a MonoBehavior reference from a parent class

#

or, well, if there's another way idk

somber nacelle
#

can you be more specific about what you mean by that?

iron vortex
#

Sure I can even provide you samples

#

hang on just a second

leaden ice
#

show the code

#

if your class derives from MonoBehaviour you needn't do anything special

#

If you have A : B and B : MonoBehaviour then any reference of type A OR B will also have everything in MonoBehaviour

iron vortex
#

The MonoBehavior class:

public abstract class Interactable : MonoBehaviour
{
    // Message displayed to player when looking at an interactable.
    public string promptMessage;

    // This function will be called from our player.
    public void BaseInteract()
    {
        Interact();
    }
    protected virtual void Interact()
    {
        // We won't have any code written in this function.
        // It's a template function to be overridden by subclasses.
    }
}
public class EventInspect : Interactable
{
    protected override void Interact()
    {
        Debug.Log("Interaction (" + gameObject.name + ")");
        // StartCoroutine(DelayCall);
        }

        IEnumerator DelayCall()
        {
            yield return new WaitForSeconds(1.5f);

            // stuff to execute with a delay
        }
}```
naive swallow
leaden ice
naive swallow
#

Nevermind that's fine

iron vortex
#

It doesn't like trying to call a MonoBehavior method

naive swallow
leaden ice
somber nacelle
iron vortex
#

I just need to know what the right syntax is for it

leaden ice
naive swallow
leaden ice
#

that's it

iron vortex
#

it just doesn't need parentheses?

leaden ice
#

it DOES need parens

somber nacelle
#

it does need them

leaden ice
#

look at my example

#

you don't have them in your commented code

naive swallow
leaden ice
#

You jumped to a lot of conclusions about inheritance etc 😵‍💫

iron vortex
#

Hold and I'll update you, also sorry if I worded it weird

somber nacelle
leaden ice
iron vortex
#

See I would have, and that was my bad, it's just I had refactored the code a lot afterwards so I no longer have the reproducible broken code

leaden ice
#

It was probably saying "DelayCall is a method group which is not valid here"

#

something like that

iron vortex
#

Ah yeah I'd say so, anyways that worked, thanks a bunch

versed marsh
#

Is there no way to normalize a Vector2Int?

rigid island
#

make into a vector2 then make it back?

versed marsh
#

yeah ill try that

late lion
rigid island
#

Ig cause it would not make sense since you will lose precision anyway since its 1 max

spring creek
#

Yes, what would the result of normalizing a vector2int with 1,1,0 be?

dusk apex
spring creek
#

Wait what?

Also, I just realized I used three values for a v2 🤦‍♂️

dusk apex
cunning burrow
#

I have a quick question, would there be a way to create a mask on a UI using a game object? or something of the likes?
I want to create maybe one big red UI on the screen and mask it with a big circle object centered on my screen, and then when the player zooms out it could like show as a enemy area

#

or would there be a better way to do it?

spring creek
# dusk apex

Ok, but then they want it as a Vector2Int. So that is the part that I wouldn't understand

swift falcon
#

Is it not a correct way to make an object move on a speed with the direction being its "forward"?

transform.Translate(new Vector3((float) Math.Cos(transform.eulerAngles.z * (Math.PI / 180) + Math.PI / 2) * speedCurrent * Time.deltaTime, (float) Math.Sin(transform.eulerAngles.z * (Math.PI / 180) + Math.PI / 2) * speedCurrent * Time.deltaTime));```
#

When I do this, the object does not move forward along its axis

#

Help is appreciated

#

Note that the + Math.Pi / 2 is there so I can have the capsule move on its proper axis

wide dock
#

Why all that math

#

transform.up

swift falcon
#

Mhhh

wide dock
#

or transform.forward, forgot which one it was

swift falcon
#

I am coming from another language so I may need to get my bearings again 😅

#

Yeah the normal I want is up

#

I forgot Unity does that

wide dock
#

Yep, so just use that

swift falcon
#

Well thank you

#

I just kind of hate that the Euler angles are deg though

#

It still happens however, when I rotate the object I do it properly do I not?

#
transform.Rotate(Vector3.forward * -(float)10 * Time.deltaTime);```
#

It is for a 2D game

#
transform.Translate(transform.up * speedCurrent * Time.deltaTime);```
My messy math simplified
#

At this point I am quite confsed

#

Maybe my camera got messed up

#

But no though...

#

Okay let me be more specific, the problem is that the object moves along an axis that rotates faster than when you rotate visually

#

Say at 0 rad the object moves up, at -Pi/4 the object moves right and at -Pi / 2 the object is already mvoing down

#

There is a 1:2 ratio so to speak

little meadow
swift falcon
#

How curious

little meadow
#

you can either do Translate(transform.up, world), or Translate(vector3.up, local)

swift falcon
#

Ralativity got it

#

Problem appears to be Solved

the solution was the following

transform.Translate(transform.up * speedCurrent * Time.deltaTime, Space.World); //Space world makes it so the object moves accordingly

Thank you ❤️

little meadow
#

That comment is extra weird

swift falcon
#

Oh?

little meadow
#

Space.World makes it so that the vector you pass is a direction in world space

swift falcon
#

Yeah I miscommunicate that

#

Okay

#

Neat

little meadow
#

so, yeah, always a good idea to keep in mind what vector is in what coordinate space

swift falcon
#

Well every engines has its quirks, it is a consideration I failed to have

little meadow
#

yeah, yeah, that is true for Translate's params, but the geometry thing is the same for all of them, hence why it's good to keep in mind 😛

swift falcon
#

I see 😄

deft meadow
#

Hi, I'm currently trying to make a grappling hook esc mechanic. Does someone know of a good tutorial for this?

lean sail
civic folio
#

if I use the new keyword on something does it get garbage collected or I have to delete it myself?

deft meadow
knotty sun
leaden ice
#

Things you have to call Destroy on are UnityEngine.Object derived classes.

civic folio
#

I don't really get heap and stack

leaden ice
#

There are also things that are IDisposable that need disposing manually

leaden ice
#

Classes get allocated on the heap

#

Structs don't except as members of classes

cosmic rain
# civic folio I don't really get heap and stack

Heap is basically where memory for reference types is allocated(including whatever data they store in them, even if it's value types). Stack is for value types that are allocated during methods execution, basically in the call stack.

lean sail
deft meadow
#

I haven't written any code myself yet, since I first wanted to understand what the basics were, but I can for sure give it a try

spring creek
flint needle
#

Whats the recommended way to modify Unity Packages so they are not treated as cache libraries?

#

Im modifying a URP shader from Unity repository but it warns changes will be deleted since it belongs to Package Cache

flint needle
leaden ice
#

It should be copied to the packages folder

#

To turn it into an embedded package

flint needle
#

Its on the packages folder in fact

leaden ice
#

Yeah but actually there or you just mean showing in the unity project window

flint needle
#

Oh right

leaden ice
#

Follow the instructions in the link for copying it from the package cache

flint needle
#

Neat, thank you

#

When it says that cached packages are immutable, when are they reverted exactly?

leaden ice
#

Whenever it's least convenient in my experience 😂

#

No idea, probably whenever the unity process detects a change, through file watchers?

flint needle
#

im grateful that rider popped a warning saying to watch out when i started editing, it would be catastrophic to lose progress

tender jolt
#

I think I posted in the wrong channel, anyways, some now how to get the angle difference in relation to pitch direction in Unity using vector3.signedAngle?

leaden ice
#

I.e. the two angles you want to compare and the normal of the plane on which you want to compare them

broken light
#

if i have an object that has no mesh but has visuals using Graphics API how can i check if its in the camera view to avoid calling draw mesh when not needed

broken light
#

thanks

jovial valley
#

Can someone help me with writing a script which finds all of the overrides of a Prefab Variant (or a gameobject in prefab form), and applies them to an instance of the base prefab?

#

Im trying to make an upgrade system which is very flexible, and this is what I want to accomplish, but what I am doing so far seems to not be working.

knotty sun
jovial valley
#

hm. is there a better way to achieve an upgrade system like this?

gray mural
knotty sun
#

you do realise that prefabs can only be modified in the editor not at runtime

jovial valley
#

the issue is that I WOULD reinstantiate the gameobject for upgrades, but some things like rotation, and other things can reference the tower, (even other upgrades), I want to stay on so it basically needs to keep changes. As such, I sort of want to log every change an upgrade makes and apply those changes on an upgrade and only those changes.

#

thats not the point - My goal is to basically make a folder which contains prefab variants which are upgrades of the prefab, then loop through and store all of the differences of the prefab varaints in something like a Scriptable Object, and then create a script which allows me to apply those differences to instantiated forms of that prefab at runtime.

gray mural
#

You want to be able to update a prefab at runtime?

spring creek
#

Why prefab variants instead of just changing yhe data?

static matrix
#

how can I get the length of an enum?

gray mural
jovial valley
#

I would even create my own asset type for this, but idk how to do that, it just seems to me that a prefab variant holds all of the differences of it automatically, so thats what I aimed to use for this

static matrix
#

sorry
should have goog'd first

gray mural
gray mural
jovial valley
# gray mural You want to be able to update a prefab at runtime?

No, there would be a prefab, it would be instantiated somewhere in the world, and then I would call Upgrade() on a script in it and it would loop through and see if It can apply the changes that a prefab variant had onto the isntantiated gameobject, then do that

#

ok ok, so how do I store data changes without using a prefab variant?

gray mural
spring creek
jovial valley
#

ok that was my idea

gray mural
jovial valley
#

alright, i guess im on the right track then

gray mural
#

Sure, just don't try to modify the original prefab

jovial valley
#

that was never the goal lol

gray mural
#

That's what you have previously mentioned