#archived-code-general

1 messages Β· Page 98 of 1

heady iris
#

stuck forever

hasty haven
#

Thanks thats probably it, so my second question:
Does refresh rate matter here if I have max fps setting right below this?

ashen yoke
#

you mean targetframerate?

hasty haven
#

The fps setting is just SetTargetFramerate()

#

Is refresh rate more of a native setting than that?

dusk apex
#

Either increment is always false, resolution count is less than one or current index is greater than resolution count.

ashen yoke
#

targetframerate is a limiter, not sure they are connected in any way to display output but ill test

#

need to know for sure

hasty haven
#

Sounds good, i'm trying to whip up a settings menu this weekend for my Next Fest demo.
Valve people wanted to play it early

#

Right now the settings are basic but I could expand to allow refresh rate

ashen yoke
#

yeah they are not tied

hasty haven
#
// See if current resolution has index
        for(int i=0; i<resolutions.Count; i++) {
            if(newResolution.ToString() == resolutions[i].ToString()) {
                currentIndex = i;
                break;
            }
        }
#

Ill just do this, theres no comparison for those structs built in

#

Maybe later on can do a dropdown or something but just need a working one for now

ashen yoke
#

wont test, it just doesnt make sense, since your game can run at 1000 fps but will display only 60, so update loop and rendering are decoupled and
targetFramerate is update capper, while resolution is actual screen output cap

hasty haven
#

I'm setting uncapped fps to 666 just because

undone beacon
#

I'm adding UI content to be parented to my scroll view, and I'm seeing these red lines in the Unity Editor for some reason. What does it mean? Also it's not rendering my Panel UIs in the scrol view, but everything else

cosmic rain
ashen yoke
#

your anchors are incorrect most likely

undone beacon
#

everything renders fine if I just instantiate as a child of the canvas. but making them the child of the scroll view cause this

#

er, causes the error in the screenshot above.

zealous juniper
#

Good morning, any/everyone! So here's my current issue with my code. In the project, my error is, "Assets\ActivateGrabRay.cs(12,31): error CS0102: The type 'ActivateGrabRay' already contains a definition for 'rightDirectGrab' and 'leftDirectGrab' too". https://paste.ofcode.org/VjWANy7GEvy7RtnfxJmPyv

ashen yoke
zealous juniper
heady iris
#

a class can't have two members with the same name.

#

therefore, you get an error: the type ActivateGrabRay already contains a definition for rightDirectGrab

ashen yoke
#

already contains

zealous juniper
#

Soo, do I just change the class names then?

ashen yoke
#

is rightDirectGrab a class name?

woeful furnace
#

Hey so I have this triangle I used a procedural mesh for which fills in these moveable points. I want to fill in the triangle to go from r g and b with their respective location. Like this

zealous juniper
heady iris
#
    public GameObject rightDirectGrab;
#

This declares a field of type GameObject

ashen yoke
heady iris
#
    public XRDirectInteractor rightDirectGrab;
#

This declares another field of type XRDirectInteractor

#

Both fields have the same name. This is illegal.

zealous juniper
#

So how do I fix it, just change one of the rights to something else?

#

and lefts

ashen yoke
#

use unique names for variables within the same class

#

in the above case you can use the type name

#
public GameObject go_rightDirectGrab;
public XRDirectInteractor xr_rightDirectGrab;
zealous juniper
#

Ahh, okay okay πŸ™‚ haha.

#

In my mind, my brain said: "Now you're learning boyo! xD"

zealous juniper
heady iris
#

well, yes, you changed the names of things

#

so now anywhere that used the old name needs to be changed to use the new name...

#

if I renamed public int foo; to public int bar;, every reference to foo would be broken

#

note that your IDE should be able to seamlessly rename variables. if your IDE is not set up properly (i.e. you aren't getting error highlighting and autocompletion suggestions in your code editor), you should really fix that now

#

!ide

tawny elkBOT
#
πŸ’‘ IDE Configuration

If your IDE is not autocompleting code
or underlining errors, please configure it:

β€’ Visual Studio (Installed via Unity Hub)
β€’ Visual Studio (Installed manually)

β€’ VS Code*
β€’ JetBrains Rider
β€’ Other/None

*VS Code's debugger plugin is unsupported.
We recommend using VS or Rider instead.

zealous juniper
#

I went to the first link website there, but how do I use it in Unity?

heady iris
#

follow the instructions for whatever editor you're using

zealous juniper
#

Will do

lapis condor
#

so I'm trying to get my project ready for vr but every project I've tried comes up with a null exception from the ParseArguements file I've tried everything I knew and dont know if im just a bozo i have the error and the code in the file.

#

`using System.Collections.Generic;

namespace Unity.PlasticSCM.Editor.ProjectDownloader
{
internal static class ParseArguments
{
internal static string CloudProject(Dictionary<string, string> args)
{
string data;

        if (!args.TryGetValue(CLOUD_PROJECT, out data))
            return null;

        return data;
    }

    internal static string CloudOrganization(Dictionary<string, string> args)
    {
        string data;

        if (!args.TryGetValue(CLOUD_ORGANIZATION, out data))
            return null;

        return GetOrganizationNameFromData(data);
    }

    internal static string ProjectPath(Dictionary<string, string> args)
    {
        string data;

        if (!args.TryGetValue(CREATE_PROJECT, out data))
            return null;

        return data;
    }

    static string GetOrganizationNameFromData(string data)
    {
        // data is in format: 151d73c7-38cb-4eec-b11e-34764e707226-danipen-unity
        int guidLenght = 36;

        if (data.Length < guidLenght + 1)
            return null;

        return data.Substring(guidLenght + 1);
    }

    const string CLOUD_PROJECT = "-cloudProject";
    const string CLOUD_ORGANIZATION = "-cloudOrganization";
    const string CREATE_PROJECT = "-createProject";

}

}`

somber nacelle
#

update or remove the Version Control package

lapis condor
somber nacelle
lapis condor
#

thanks probably should of thought about that

lunar forum
#

When you instantiate a game object, how is the Instance ID determined? I ask because I am spawning enemies every X seconds and out of curiosity wanted to debug.log the instance ID's and noticed that 1 would be a positive number, and the rest (theoretically for as long as I would let the game run) were negative numbers.

somber nacelle
lunar forum
#

Hm. Interesting. I have to remember to check the docs first. I default to coming here for what end up being very easy to answer questions if I had just read the docs first.

heady iris
#

they're often enlightening!

#

although it can be hard to know where to look, exactly

#

i guess i'd just google "unity instance id" in this case

#

your google results will vary with your search history, but I do get GetInstanceID as the second result

#

(on bing lol)

#

tfw we have a google emoji but no bing emoji

#

this is so sad

terse raven
#

does anyone know a good tutorial for a menu thats short but useful?

lunar forum
# terse raven does anyone know a good tutorial for a menu thats short but useful?
BMo

Hoo boy, this was more of a challenge I wanted to do myself, was getting tight on time near the end.

I wanted to try to show how to setup something every game needs, a main menu, in as concise of a way as possible in a Unity Tutorial. I also tried to explain additional things like general UI advice in Unity, as well as Scene management (loadin...

β–Ά Play video
terse raven
#

tyvm

lunar forum
#

That one gets to the point pretty quick.

terse raven
#

nice

lunar forum
#

Isn't very pretty

#

But works

terse raven
#

well, only if it works, right?

#

its good

#

if it works

#

ig

#

alr

#

pretty much to the point

#

good

lunar forum
#

Yep. Then it's basically rinse and repeat. I use that method for slapping stuff together just to get a MVP together.

tiny turret
#

i have a question for you programmers

#

what is the easiest way to find people to make a game inspired in another game that people barely remember of? (Little Big Planet is the game im talking about)

somber nacelle
#

!collab

tawny elkBOT
tiny turret
#

or well, a franchise of games

#

i alredy have a post there

somber nacelle
#

way to find people to make a game
that's literally what collaborating is.

tiny turret
#

so if that works thats that

tiny turret
#

but if that doesnt work i mean

somber nacelle
#

well if the resources the bot linked don't work out for you then you can try and find people elsewhere πŸ€·β€β™‚οΈ

tiny turret
#

nvm

#

Like this?

#

yes

wise kindle
#

I'm making a game where if you interact with a sink, it makes the object you're holding wet. Is there a specific line of code I could use that could make the object watery/reflective?

potent sleet
wide terrace
#

It... depends on your application. Each cell should have a reference to the same object... if you want it to. But then you're saying they should all be unique. I'm not clear on your intended outcome, nor what you currently have in place

cosmic rain
#

I'm not sure if that does anything at all

#

What does Get return?

#

Probably doesn't matter what it returns. Unless maybe the returned object overrides the assignment operator.

wide terrace
#

But what are you calling "a reference" here?

cosmic rain
#

basically it creates a local variable referencing whatever you Get(). Then you assign the value to that variable. When the execution goes out of scope the local variable is destroyed.

#

This is the same as your code:

var reference = Get(a, b);
reference = value;
#

The original element that you get or the collection that holds it are not affected in the process.

wide terrace
#

Tangent: can you actually "return a pointer" in C#? I know I could do it in the C world, then assign a new value to the deferenced pointer - but I haven't seen that in C# as of yet

cosmic rain
#

Before even tackling your issue, your code is invalid. It doesn't do anything...

cosmic rain
wide terrace
cosmic rain
#

Is that not the actual code that you're using?

#

When asking for help, please provide the actual code, because some context might be lost otherwise...

#

They're probably gonna say the same.

#

*Going to have a look in the C# discordπŸ‘€

wide terrace
#

I'd like to follow along as well... I need uh.... !csharp

tawny elkBOT
#

You can format your multiline code block with C# highlighting! Just add cs to the start of it. Highlighting example below!

class Fluffs : FluffyCat
{
    public void PetCat ()
    {
        Debug.Log ("Petting Cat.")
    }
}
wide terrace
#

!cs

tawny elkBOT
#

You can format your multiline code block with C# highlighting! Just add cs to the start of it. Highlighting example below!

class Fluffs : FluffyCat
{
    public void PetCat ()
    {
        Debug.Log ("Petting Cat.")
    }
}
wide terrace
#

bah

cosmic rain
wide terrace
#

Thank you 😁. I know there's a command to get that invite, but I clearly fumbled

cosmic rain
#

This is totally different to what you shared though

wide terrace
#

Sure... my confusion was assigning a value to a value returned from a method call though

#

interesting

cosmic rain
#

it returns a ref okay.

#

in C# by "reference" we imply an instance of a class. The ref keyword is indeed similar to C++ references.

#

So, if you want to clone the object, you need to construct a new instance and copy all the fields from the original instance.

#

If you're dealing with unity Objects there's the Instantiate method, that basically clones the instance.

#

Then you'll need to construct a new instance manually with new YourValueClass(params)

#

If there's polymorphism or interfaces involved, you could define a Clone method on the base class/interface and implement it in each of the subclasses.

#

Yeah, like a copy constructor.

#

There are many ways to go about it. It shouldn't be too different to cloning heap objects in C++.

#

Umm... What's Array2D.Fill() and Get again?

#

Yes. It does that.

#

You'll need to loop the array and assign a new Wall() to each element if you want them to be unique.

#

Probably. I don't think you should be thinking about performance at this stage...

#

Then maybe use structs? It kinda feels like you're diving head-deep into something complicated without understanding C# properly. You can't apply the same logic as C++. Gotta understand that.

#

C# and unity can be as performant as C++. If you do your learning properly.

glad plover
#

If an item is given, it should not be added to the inventory and the ammunition county should increase. How to solve this?

daring lake
#

hey im trying to make a bullet shoot and hit the player to take damage and then delete itself, it isnt deleting itself and it isnt doing damage either


using UnityEngine;

public class EnemyBullet : MonoBehaviour
{
    public int damageAmount;

    public float bulletSpeed = 5f;

    public Rigidbody2D theRB;

    private Vector3 direction;

    // Start is called before the first frame update
    void Start()
    {
        direction = PlayerController.instance.transform.position - transform.position;
        direction.Normalize();
        direction *= bulletSpeed;
    }

    // Update is called once per frame
    void Update()
    {
        theRB.velocity = direction * bulletSpeed;
    }

    private void OnTriggerEnter2D(Collider2D other)
    {

        if(other.tag == "Player")
        {
            PlayerController.instance.TakeDamage(damageAmount);

            Destroy(gameObject);
        }
    }
}
cosmic rain
#

It depends on the use case. There are situations where a reference would be more performant.

glad plover
# glad plover If an item is given, it should not be added to the inventory and the ammunition ...
    {
        [SerializeField] private AmmoClipItem ammoItem;
        [SerializeField] private Rigidbody _rigidbody;
        [SerializeField] private PickUpSnd pickSnd;             // access to the pick up sound class
        [SerializeField] private GameObject outline;

        private readonly float _impulseStrength = 200f;

        public Item Item { get => ammoItem; set {} }

        public PickUpSnd PickSnd
        {
            get => pickSnd;
            set => pickSnd = value;
        }

        public GameObject Outline
        {
            get => outline;
            set => outline = value;
        }

        private void OnEnable()
        {
            gameObject.name = ammoItem.Name;
        }

        #region Server

        [Command(requiresAuthority = false)]
        public void CmdInteract(GameObject playerObject)
        {
            var isSuccess = PickupItem(playerObject);
            _rigidbody.AddForce(Vector3.up * _impulseStrength);
            RpcInteract(playerObject, isSuccess);
        }

        private bool PickupItem(GameObject playerObject)
        {
            var armorManager = playerObject.GetComponent<ArmorManager>();
            if (armorManager.IsNoSpaceForAdditionalAmmo(ammoItem.ammoType, ammoItem.AmmoCount)) return false;

            armorManager.GiveSomeAmmo(ammoItem.ammoType, ammoItem.AmmoCount);
            Destroy(gameObject);

            return true;
        }

        #endregion

        #region Client

        [ClientRpc]
        public void RpcInteract(GameObject playerObject, bool isSuccess)
        {
            if (!isSuccess) return;
            
            PickSnd.PlayPickUp();
            Destroy(gameObject);
        }

        #endregion
    }```
ashen yoke
#

depends

#

a giant chunk of memory you have to copy all the time vs a null test or ref compared

#

whats that pattern called flyweight?

#

also AOS/SOA

obtuse portal
#

😐

ashen yoke
#

can also be corrupted asset

obtuse portal
# ashen yoke broken library most likely

Should I kill the Unity task, delete the library and re-open? The issue originally was that Visual Studio package was giving errors after I upgraded to 2.0.18

ashen yoke
#

roll it back to 0.14 through manifest edit

#

whats the project size in gb?

obtuse portal
#

2.44GB

ashen yoke
#

also .vs and temp for good measure

#

and the csproj and sln

obtuse portal
ashen yoke
#

what i mean is that you dont need to keep state of each cell in the cell

obtuse portal
#

Daaang

#

And you mean the .vsconfig file?

ashen yoke
#

you can share same cell data class reference and use ref comparison and allocate closely the cell data, swapping with new instances only on persistent changes

ashen yoke
#

what i wrote verbatim

obtuse portal
#

Ohh the folder

ashen yoke
#

"show hidden files" if you dont already

obtuse portal
#

Yeah I see it

ashen yoke
#

yeah even with ref you are bumping into struct length

#

will it fit into a cache line? how many reads you will need to read the whole thing?

#

yes and can you guarantee it?

#

with object references you can share a single instance over many cells

#

it will remain in cache

#

its pretty much the same exact thing

#

class array in c# is the same as ref/ptr array in c++

#

same problems

#

cache lines, copy semantics

#

SOA is great also the read lines from each array will remain in cache, but you can layer grid properties

#

i.e. at any point you append another array with some primitive type

#

to express some new cell property

cosmic rain
#

If it was easier, you probably didn't really do that much for performance in it anyway.

#

So no point being picky about it in C# either

ashen yoke
#

i feel like my point is not being cached

cosmic rain
#

Then implement it.πŸ€·β€β™‚οΈ

ashen yoke
#

System.ICloneable is a thing

#

extension methods as well

obtuse portal
#

Also the manifest file solution. Can't believe it was that easy

ashen yoke
#

rule of thumb for the future if it takes more than 30 mins without going into "asset x, asset y..." nuke it

#

probably even shorter just hard to tell since project size matters

#

but id guess anything below 10 gigs is a safe bet if its around 5-10 minutes

#

also there are scenarios where you simply cant find the corrupted asset

#

there are thousands of them and 1 is broken and break import

#

its important to organize project, and dont keep redundant "maybe will use later" assets in the project

obtuse portal
#

Agreed. This is sort of a throwaway prototype so I've not been as vigilant as I normally would be. Just frustrating as hell how many projects I've had to nearly abandon because of the engine itself going haywire.

#

Back in business for now though, so thanks again!

ashen yoke
#

99.99% of cases you can fix

cosmic rain
#

You need to explicitly define constraints for T in your method

#

You're probably confusing generics with C++ templates. They're not the same...

#

If you want to keep on developing with unity and C# you'll need to learn it properly...

simple sable
#

Hey guys, I have a small problem here.

So at some point in my code I start a coroutine, and this coroutine has a line that looks like this "yield return new WaitForSeconds(seconds);". So the coroutine waits that amount of seconds before running the code that comes after.
But I also make a check in Update() and if the condition is meet then I try to stop the coroutine with StopCoroutine("CoroutineName"); because I don't want the code that comes after that yield to run anymore.

Though, for some reason, the coroutine does not stop, even though the condition is meet (and, the rest of the code in the coroutine gets executed).

I would really like to know what I'm doing wrong.

potent sleet
#

eg

Coroutine myCoroutine;

void TheMethod(){
myCoroutine = StartCoroutine(MyRoutine());}

void Update(){
if(stuff)
StopCoroutine(myCoroutine);
}```
swift falcon
#

public GameObject cubes;

public static void Use (string itemName) {

    if (itemName == "wow1") {

        cubes.SetActive(true);
#

i get error that cubes isnt static its public but im trying to refernce it

#

in a static thing

potent sleet
#

and you can't assign it in the inspector if it's static

simple sable
swift falcon
#

if i make cubes static then i cant drag it onto the inspector thing

#

frik

potent sleet
swift falcon
#

cud i reference the object in scene then like

#

StorefrontDemoScene.Main.wowEnabled.SetActive(true);

simple sable
#

Oh, I see. Thank you very much!

potent sleet
#

just make the instance of it static

#

so you can access public methods/whatever else public, directly through that instance

swift falcon
#

uh

#

public static GameObject cubes;

#

like that?

#

if i do that

#

i cant drag it

#

to inspector

potent sleet
#

no that's not the instance of the class..

#

the class this is in ?

swift falcon
#

using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System.Runtime.InteropServices;
using UnityEngine.SceneManagement;

public class UseItem : MonoBehaviour {

public GameObject cubes;




public static void Use (string itemName) {




    //Debug.Log ("Custom item usage executing for item: " + itemName);

    if (itemName == "wow1") {

        cubes.SetActive(true);
#

its in public class

potent sleet
#

like [SerializeField] private UseItem useItem; or public UseItem useItem

#

then just drag the script in

#

access it this way

swift falcon
#

uh

#

i get errors if i dont have that part static

#

cuz it came with a bunch of other like scripts n stuff

#

uh i can do

#

GameObject.Find("wowEnabled").SetActive(true);

#

but the problem is it cant find it cuz its not enabled

#

hm

#

it can disable it tho

#

i use playmaker for scripts

#

so i enable them then have the playmaker do stuff

potent sleet
#

you seem to misunderstand some fundamental c# concepts

broken light
#

what is a way to use inspector to filter "types" of components i want to find from physics colliders

#

i want to collect a list of all objects that have a component that i want to decide from a list of types

#

not sure how i would set that up though

#

i cant use layers either

wet saddle
#

I have an player appearing animation, which should be played on start. But I think it's playing even before the scene is loaded and I am not able to see it. Is there any way to delay it?

gray mural
gray mural
broken light
#

No I said components

#

Of types I care to select

gray mural
#

so you just need to find GameObjects and then use .Select of LINQ I guess

#
GameObject[] allGameObjects = FindObjectsOfType<GameObject>(includeInactive: true);

// for example
GameObject[] withRigidbody = allGameObjects
  .Where(w => w.GetComponent<Rigidbody>() != null).ToArray();
leaden ice
#

If you're doing that why not just use FindObjectsOfType<Rigidbody> in the first place?

gray mural
#

ofc you can do smth like that too:

Rigidbody[] rigidbodies = FindObjectsOfType<Rigidbody>(includeInactive: true);
broken light
#

My current approach is a class with an enum

#

So I can bit flag to get all objects with the signature but it's annoying having add enums for new components

knotty sun
#

how about

List<Type> types;
List<Component> selected;
Component[] components = FindObjectsOfType<Component>
foreach (Component c in components) {
if (types.Contains(c.GetType()) selected.Add(c);
}
hoary quarry
gray mural
hoary quarry
tawny elkBOT
#
Posting code

πŸ“ƒ Large Code Blocks
Large code blocks should be posted as links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/
https://paste.myst.rs/, https://hastebin.com/

πŸ“ƒ Inline Code
Surround code with three backquotes. Not quotation marks.
To get C# formatting the first line should only contain cs or csharp.
Add a comment with a line number if there is an error message.
```cs
// Your code here
```
Do not share screenshots of code unless requested.

broken light
#

Into the list

knotty sun
#

Type is, iirc not serializable by default

#

you can use nameof and Type.GetType to convert between strings and actual Types

rotund burrow
#

how would i check an area for the highest y point in there optimally? assuming you can do this by just raycasting from above everywhere

rotund burrow
#

imagine you have a black and white heightmap and you want to get the whitest point. i'm not working with them just making an analogy.

rotund burrow
#

it's collider based? the area can have multiple objects

gray mural
rotund burrow
#

i mean it cant be collider based

#

anyway i think i'm overcomplicating it

#

i just need to do a step down function. teleporting the player down on steps

gray mural
#

@rotund burrow

Collider collider = GetComponent<Collider>();

Vector3 maxPoint = collider.bounds.max;
rotund burrow
#

so the idea was to check if player is in air and its y velocity is around 0, then check if the distance to the ground is short then you can tp there

gray mural
gray mural
rotund burrow
#

yeah i know how to code it the problem is the ground isnt flat

gray mural
warm shadow
#

How do I make it so a recursion function breaks out if it has run x amount of times?

warm shadow
#

yes i tried that, but it never breaks out

#

Ahh, never mind, fixed it

gray mural
rotund burrow
gray mural
rotund burrow
#

what distance?

gray mural
#

according to our previous conversation

rotund burrow
#

steps, stairs

#

it's walking downstairs

gray mural
rotund burrow
#

i dont get you

gray mural
#

I think I do not get you

#

say what you need to do

#

otherwise I should guess

lyric panther
#

what's rendered vs what's shown. there's a lot of extra renderering done that's just hidden. is there a way for the camera to only render a certain portion of the screen? similar to blenders "render region" function

cold parrot
lyric panther
#

?

#

that's what i'm trying to do

#

The current rendering is wastful, it's rendering regions that aren't being shown, i'd like to render only was visable

cold parrot
#

I don’t understand, just change the fov or focal length

lyric panther
#

it's a portal effect, i have two cameras, one main camera and one rendering the view through the portal. the main camera is on the left, the portal camera is on the right. the portal camera needs the same FOV as the main camera otherwise the portal effect is ruined

rotund burrow
#

okay let's try again. Player is going downstairs i want to teleport it on the next step instead of it falling there. The problem is checking the distance between player and next step. You cant just do one raycast down, because there might be holes in the ground or the step after next step (which is lower and that will teleport you inside of the stairs). IDBB you cant check distance between transforms, let's say all of the ground is one object.

lyric panther
#

the red regions are being rendered when they don't need to be rendered

#

the areas shaded in red are never shown and so are a waste of time being rendered

#

for one portal it's not that bad but when you have a few it tanks performance

gray mural
#

please, show your stairs, cause I don't really get why you cannot use Raycast

rotund burrow
#

it's like the image above

gray mural
#

and also say, where should player be teleported here?

rotund burrow
gray mural
#

and spawn player on the hitInfo's position

rotund burrow
#

okay i think this discussion just isnt worth it. I'm gonna do a raycast check from behind the player. meaning the point of the collider where -velocity hits it. it's not a general solution but will work for now

gray mural
#

or if that's too hard, you can decrease player's position until they are grounded

rotund burrow
#

i have a cylinder so you would have to do like 9 raycasts and then compare the distance of each one

gray mural
rotund burrow
#

right i can just... push the player down

#

it would be similar to teleporting

#

just a fast push, funny how i didnt think about it

gray mural
rotund burrow
#

yeah i know how to code. thanks for your idea but you're being condescending.

gray mural
dawn nebula
#

Does anyone have a resource for getting repeating textures for things like distortion/noise maps?

rotund burrow
hexed pecan
#

Offsetting a UV coordinate with noise will produce some nice distortion too

hexed pecan
#

Or CapsuleCast but usually SphereCast is enough

#

Don't have to worry about holes smaller than your capsule because the sphere won't fit through

cold parrot
lyric panther
#

that's what i'm trying to do but it renders the whole scene

lyric panther
silver wharf
#

why is MonoBehaviour undefined and what can i do about it?

hexed pecan
tawny elkBOT
#
πŸ’‘ IDE Configuration

If your IDE is not autocompleting code
or underlining errors, please configure it:

β€’ Visual Studio (Installed via Unity Hub)
β€’ Visual Studio (Installed manually)

β€’ VS Code*
β€’ JetBrains Rider
β€’ Other/None

*VS Code's debugger plugin is unsupported.
We recommend using VS or Rider instead.

warm shadow
#

Why is the ObjectList empty, then i return it, but the lists i join are not empty, Code:

public WaveObjectData[] GetObjects()
{
    List<WaveObjectData> objectList = new List<WaveObjectData>();
        
    for (int i = 0; i < tileTypes.Length; i++)
    {
        objectList.Union(tileTypes[i].objectDataList).ToList();
    }

    return objectList.ToArray();
}
hexed pecan
#

Maybe you want objectList = objectList.Union(...).ToList();

warm shadow
hexed pecan
#

Yepp

warm shadow
#

okay, thanks, ill try it

gray mural
#

does anyone know, how to check when user is holding the mouse button while over the GUIElement or Collidion in script?

#
// this code works just when button is pressed (the target is destroyed then)
// I need it to be destroyed, when the button is held too

private void OnMouseDown()
{
    if (CompareTag("GoodTarget"))
    {
        Instantiate(explosionParticle, transform.position, explosionParticle.transform.rotation);

        scoreManager.ChangeScore(1);
        Destroy(gameObject);
    }
    else spawnManager.GameOver();
}
hexed pecan
#

Oh wait does Union check for unique values

#

If thats the case and its needed then nvm

warm shadow
warm shadow
hexed pecan
#

Yeah ok go with AddRange

gray mural
indigo haven
#

Hey good day.
Today i present you a question with some math content (so i need help xd).
I want to get from a list of n elements at least 1 element at random an n elements at maximum and i dont want to have the same probability for each of the elements to be selected.
Any ideas?

hexed pecan
hard estuary
hexed pecan
heady iris
#

there's a separate graphic raycaster component

hexed pecan
#

So many raycast functions

gray mural
#

ok, so I have this. Now I need to check UI's tag and destroy it if it's tag is "GoodTarget"

private void Update()
{
    if (Input.GetMouseButton(0))
    {
        if (EventSystem.current.IsPointerOverGameObject())
        {
            Debug.Log("Clicked on the UI");
        }
    }
}

How do I get information of that UI

dusk apex
heady iris
hexed pecan
gray mural
dusk apex
#

Also, why not use the pointer callback instead of polling in Update?

hexed pecan
heady iris
#

nice

cold parrot
dusk apex
brave radish
#

Hi im triying to make a 2d game with top down view and I'm trying to get my player to get in and out of the car,does anyone know how to do it?

gray mural
lyric panther
hexed pecan
#

Even AAA games can't get "getting in and out of cars" right lol

dusk apex
gray mural
heady iris
#

I would say to start with a simple teleport: you hit a button, and now you're in the car

#

then, you can figure out how to make the player just...lerp into the car

#

and then maybe throw in sound and animations for a door opening

hexed pecan
#

Yep, make it work first. Then make it look smoooth @brave radish

dusk apex
brave radish
narrow summit
#

I'm trying to see if my player is colliding with any of the colliders that are children of one gameobject. From everything I've seen online this should work, and the "s" that separates the two similar methods is clearly there. However, this is still acting like GetComponent (singular) and is only giving me the collider of the first child among them. How do I get them all?

hexed pecan
desert shard
#

my vs is constantly getting stuck on errors that don't exist. is there a way to stop this from happening? restarting the IDE every 10 minutes is infuriating

warm shadow
#

So I'm having an issue, but its across 4 different scripts, should I just share them all on separate paste sites?

hexed pecan
#

Yeah put the scripts in separate links

warm shadow
#

okay

brave radish
hexed pecan
# brave radish

Ok so for this to work, you would have to press down space on the exact physics frame that you enter the collision

desert shard
#

you also need to configure IDE

hexed pecan
#

I would use a trigger collider, detect the availability in OnTriggerEnter2D/Exit2D, check the input in Update and do the action only if something is available

#

Or use collisions but change GetKeyDown to GetKey... But having to touch the car isn't the best for game feel

warm shadow
#

So, I'm trying my hand at a wave function collapse, and it works great when using the object list in this script: https://gdl.space/tamawuduwa.cs, but I wanted to change over to a TileType system, to cut down the setup time, so I don't have to set up each rotation for each tile, and also store them as Scriptable objects, but now it is not working with my new system, then I check it in the foreach loop in script above. Here are the other ones: TileType: https://gdl.space/evahocikab.cs, WaveObjectData: https://gdl.space/yahonoyuwe.cs. Can anybody help me, i know it's quite a lot, but I'm really stuck.

#

BTW the CreateOtherTiles() is run in an editor script using a button in the inspector.

heady iris
#

what does "it is not working" mean?

warm shadow
#

it means that the tiles that should be the same are not the same and my generation scripts cant use them, i check for this on line 24 in this script: https://gdl.space/tamawuduwa.cs

heady iris
#

by default, comparison is done by checking for reference equality

#

you only get true if the two things are literally the same object

warm shadow
#

okay, sΓ₯ not of the values of the things are the same?

swift falcon
#

is there a way to tell 2 different scriptable objects apart?

#

for instance

#

one is a consumable and one is a armour object

heady iris
#

then you're checking if every element in that list is also in objects?

heady iris
#

i'm guessing they have the same type

calm heath
#

how would I display the points that I got on one scene to another scene. Like how would I make the points I got go to the death scene

swift falcon
#

both derive from 1 base scriptable object class πŸ˜„

heady iris
#

2: did you read my answer?

calm heath
#

oh sorry didnt know you were talking to me

warm shadow
#

yes, each TileType has a list of WaveObjectData, that is the different orientation of that Tile, Then then get added together in one big list, that holds them all, that is then referenced with my old system of just making all the WaveObjectData by hand. The old method works, but the new doens't and i don't see what the difference is

heady iris
#

it'll be because objects has different instances than objectList

#

even if the data is the same

#

they are two unrelated objects

#

so, you'll need to implement your own Equals method if you want to test for equality properly

swift falcon
heady iris
#

you can always use the is operator

#

i do that for my own game which also has an inventory system w/ multiple derived types :p

warm shadow
#

okay, but i still don't see what the difference would be from my generation script, that just call the GetObjects() method, to get the list, and with the old objects is works, but with the new objectList it doesn't

heady iris
#

it feels weird to do that -- it usually indicates you're doing OOP wrong

heady iris
#

strictly because the elements of objects aren't contained in objectList?

warm shadow
#

because it doesn't generate the world with the objectList, but it does with the objects, and i thought if i checked if they were the same, which they should, then i might come closer to the issue

heady iris
#

you can only check if they're the same if you implement a meaningful Equals method

#

!code

tawny elkBOT
#
Posting code

πŸ“ƒ Large Code Blocks
Large code blocks should be posted as links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/
https://paste.myst.rs/, https://hastebin.com/

πŸ“ƒ Inline Code
Surround code with three backquotes. Not quotation marks.
To get C# formatting the first line should only contain cs or csharp.
Add a comment with a line number if there is an error message.
```cs
// Your code here
```
Do not share screenshots of code unless requested.

keen solstice
#
using System.Collections.Generic;
using UnityEngine;

[RequireComponent(typeof(BoxCollider2D))]
public class clickable : MonoBehaviour
{
    void OnMouseEnter()
    {

        if (gameObject.tag == "inventory")
           {Debug.Log("Add to inventory");
            mousecontrollerscript.instance.Pickup();}
        else if(gameObject.tag == "viewable")
        {
            mousecontrollerscript.instance.View();
            Debug.Log("view");
        }
        else
        {
            mousecontrollerscript.instance.Default();
    }

        }
    


    void OnMouseExit()
    {
        mousecontrollerscript.instance.Default();
    }
}

(I feel like this is a very verbose way to get the cursor to change on entering certain objects. any easier ways?)

heady iris
#

knock it down to one kind of tile

swift falcon
#

i didnt know there was an is operator tbf ty ❀️

heady iris
#

also handy:

#
if (obj is FooType foo) {
  foo.Whatever();
}
swift falcon
#

not too sure how i would match it against ArmourItem tho ngl

#
if(nearest_slot is ArmourItem) {
                // do code
}
#

be like this?

#

or this

if(nearest_slot.GetItem() is ArmourItem kk) {
                // do code
}
#

i think the second one makes more sense actually

#

ill test it out with a debug.log

heady iris
#

i mean, that depends entirely on how your classes work

#

what is the type of nearest_slot?

swift falcon
#

its a class that holds slot information

#

but can also return the item

heady iris
#

is it a parent class of ArmourItem?

#

if not, then that first one would be bogus

swift falcon
#

First one is probably bogus

#

or most likley bogus

heady iris
#

your IDE would probably complain about it always being false

swift falcon
#

Yeah came up with a yellow warning

#

ill try this for now

#

ill see what output i get

heady iris
#

the result of nearest_slot.GetItem() will be assigned to kk if the cast works

swift falcon
#

ahh i see

#

thats pretty handy

#

is working fine πŸ˜„

#

also, i dont know if my system is practical. i have a script called ArmourIdentifier that sits on the armour slot and you can set it to what the armour slot is for instance if its a helmet in the inspector you can set it, then i reference that script and check it against the SO

warm shadow
#

Okay so i found an issue, in this script, the FourSides doesn't rotate the sides correctly, https://gdl.space/evahocikab.cs, here is a picture of the outputs: is should have rotated it so it is north and west that are road, but it doesn't

heady iris
#

i had a lot of fun implementing this exact thing in an ECS game..

#

lots of ways to screw up the rotation, specifically

warm shadow
#

Okay, but I really don't see the issue, it look all fine to me...

swift falcon
#

to compare 2 enums do you need to cast them to a int?

warm shadow
#

Don't know what i did, but it works now

#

thanks for all the help : )

heady iris
#

i was writing code to figure out how to rotate two tiles to make certain faces touch

#

it was very messy

heady iris
warm shadow
#

yeah, I renamed a variable and then it worked, no idea why

heady iris
#

i'm guessing you want equality checking?

heady iris
#

so it was a nuisance to reason about

narrow summit
swift falcon
heady iris
#

show your code.

#

it's fine for me if I compare two enums

#

e.g. EnumType.A < EnumTypeB or EnumType.A == EnumType.B

#

not so much if one is an int

swift falcon
#

i think its becauae

#

there techincally 2 types but same values

heady iris
#

again, show your code.

deep fable
#

Hi! I am using position handles to move the target position (a Vector3) of an IK system, but apparently when I use the handles the new position is not serialized. Like if I change the position and then I enter in play mode, the change is there. But when I exit from play mode, the position is reverted back to the previous one

#

This is the code of the position handle:

#if UNITY_EDITOR
    [UnityEditor.CustomEditor(typeof(FabrikSolverAuthoring))]
    public class CustomEditor : Editor
    {
        public void OnSceneGUI()
        {
            var authoring = target as FabrikSolverAuthoring;
            authoring.Target = Handles.PositionHandle(authoring.Target + authoring.GlobalOffset, Quaternion.identity) - authoring.GlobalOffset;
        }
    }
#endif
#

It basically makes position handles useless since what I do is reverted back after 1 play

heady iris
#

you need to wrap that in a change check

#

you should mimic what the example code does

deep fable
#

Oh thanks, I'll try!

heady iris
#

i'm guessing that, if you don't do this, unity never notices that you made a change

#

thus the behavior

deep fable
#

And if I have 2 handles in the same script (for 2 different variables)? I do a EditorGUI.EndChangeCheck for both of them?

heady iris
#

i dunno about that -- i guess i'd just put both in the same change check

deep fable
#

It works, thanks ❀️

gray mural
#

Does anyone know how to create nice mouse effect, when dragging the left button?

#

I mean drawing with mouse actually

heady iris
#

a what?

#

so you want to be able to paint with the mouse, basically?

gray mural
#

that's like additional effect

#

when mouse is moving, it should have like tail (I guess)

heady iris
#

oh, you want a mouse trail

#

you could use a TrailRenderer

gray mural
knotty sun
gray mural
#

how to I "name" those type of methods?

volumeScrollbar.onValueChanged.AddListener(_ =>
{
    // do smth
});
#

like "delegates" or "listeners"?

knotty sun
#

you dont, they are lambda expressions, they not have a name

knotty sun
#

no, lambda if you need one

gray mural
heady iris
#

it's a lambda

#

if you're asking what to call it

delicate crane
#

Hi,
I'm currently working on a tilemap based game in unity and tried to create a custom RuleTile.
In this I override the RuleMatch function like this:

public override bool RuleMatch(int neighbor, TileBase tile)
    {
        switch (neighbor)
        {
            case Neighbor.This: return CheckThis(tile);
            case Neighbor.NotThis: return CheckNotThis(tile);
            case Neighbor.LowerLevel: return CheckLowerLevel(tile);
        }
        return base.RuleMatch(neighbor, tile);
    }

Is there any way to get information about the (relative) position of that neighbor that is being checked in regards to the tile with that script on it?

desert shard
#

transform.parent.DORotate(startingRot, 0.2f, RotateMode.FastBeyond360); how do you do a full 360 revolution tween on a single axis with dotween? since the start and end rotation will be the same

hidden plank
#
    {
        GameObject obstacle = Instantiate(prefab, transform.position, Quaternion.identity);
        obstacle.transform.postion += Vector3.up * Random.Range(minHeight, maxHeight);
    }```
`Assets\spawnObstacles.cs(25,28): error CS1061: 'Transform' does not contain a definition for 'postion' and no accessible extension method 'postion' accepting a first argument of type 'Transform' could be found (are you missing a using directive or an assembly reference?)`
Why does it say transform doesn't habe position
heady iris
#

which line is the error coming from?

#

oh

#

postion

#

that is not how you spell "position"

hidden plank
#

oh somehow i missed that lol

#

thank you

heady iris
#

i mostly just use autocompletion

hidden plank
#

for some reason i dont get autocompletion on visual studio

heady iris
#

ah, you need to fix that!

#

!ide

tawny elkBOT
#
πŸ’‘ IDE Configuration

If your IDE is not autocompleting code
or underlining errors, please configure it:

β€’ Visual Studio (Installed via Unity Hub)
β€’ Visual Studio (Installed manually)

β€’ VS Code*
β€’ JetBrains Rider
β€’ Other/None

*VS Code's debugger plugin is unsupported.
We recommend using VS or Rider instead.

heady iris
#

it will make your life much easier

#

follow the instructions from top to bottom, to make sure that everything is set up correctly

#

although, before you start, try clicking "Miscellaneous Files" in the top left

#

if that has no other options, then go ahead and do the steps

#

but it's possible it's all set up properly already, and that you just don't have the project selected

hidden plank
#

I will

#

thank you so much

#

is there a big difference between using visual studio code and visual studio for unity?

near monolith
#

is this where is ask whats wrong with my code?

hot torrent
#
            for (int i = 0; i < SMR.materials.Length; i++)
            {
                SMR.materials[i] = PhaseMat;
                Debug.LogError("assogner mat " + SMR, SMR.gameObject);
            }
        

This code does not change the material SMR.materials[i] properly to PhaseMat... any idea why?

heady iris
#

do you have any other code that could be assigning to the material slots?

simple egret
hot torrent
heady iris
#

!code

tawny elkBOT
#
Posting code

πŸ“ƒ Large Code Blocks
Large code blocks should be posted as links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/
https://paste.myst.rs/, https://hastebin.com/

πŸ“ƒ Inline Code
Surround code with three backquotes. Not quotation marks.
To get C# formatting the first line should only contain cs or csharp.
Add a comment with a line number if there is an error message.
```cs
// Your code here
```
Do not share screenshots of code unless requested.

simple egret
#

Well, completely ignored the instructions in the read-me altogether

hot torrent
#

._."

heady iris
#

zoop

balmy dove
#

https://gdl.space/lapokigeto.cs
I'm trying to make it such that when I press Boost, and only Boost once, will cause the character to hop (ie. If I tapped Melee and Shooting, the mech should not hop, and double tapping or holding it down will cause it to not hop as well)
but currently while i got the latter done, regardless of combination I did the chara will always hop as long as the boost button was pressed

heady iris
#

please

simple egret
#

Please post !code correctly

tawny elkBOT
#
Posting code

πŸ“ƒ Large Code Blocks
Large code blocks should be posted as links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/
https://paste.myst.rs/, https://hastebin.com/

πŸ“ƒ Inline Code
Surround code with three backquotes. Not quotation marks.
To get C# formatting the first line should only contain cs or csharp.
Add a comment with a line number if there is an error message.
```cs
// Your code here
```
Do not share screenshots of code unless requested.

heady iris
#

that was twice in a row now

ancient sail
#

my bad

simple egret
#

Not sure if this is the cause, but the direction you pass as argument 2 to Raycast should be normalized. That way its length doesn't depend on the distance between the two objects

#

Also, your GetComponent in your if statements are not needed, as .collider is already a Collider2D

ancient sail
simple egret
# balmy dove help pls?

In FixedUpdate, all of your new WaitForSeconds don't do anything here. You need to be in a coroutine and you need to yield return them in order to have an actual wait happening

#

Here all your code executes at once

balmy dove
#

do I just make the FixedUpdate start a coroutine with the coroutine store everything else in that case?

#

(so that's why yield return new causes the visual studio error to ring)

simple egret
#

I'd make a coroutine with an infinite loop in it, and start it once, in Awake or Start

balmy dove
#

alright

simple egret
#

And for the error, yielding can only be done in a coroutine so that's probably why

silver wharf
#

!ide

tawny elkBOT
#
πŸ’‘ IDE Configuration

If your IDE is not autocompleting code
or underlining errors, please configure it:

β€’ Visual Studio (Installed via Unity Hub)
β€’ Visual Studio (Installed manually)

β€’ VS Code*
β€’ JetBrains Rider
β€’ Other/None

*VS Code's debugger plugin is unsupported.
We recommend using VS or Rider instead.

simple egret
#

With that set up, make sure you get the right object detected

regal epoch
#

hey im getting this error:
Gradle failed to fetch dependencies.
what do i have to do get rid of this error

simple egret
regal epoch
#

no trying to resolve in unity error

somber nacelle
regal epoch
#

but im not trying to build it to my phone, so how does it have to do with mobile? sorry ive been using unity for 3 weeks now im a bit new

somber nacelle
regal epoch
#

no, it happens when i try to resolve the project

#

building to my phone doesn't have any problems

somber nacelle
#

wtf does "resolve the project" mean

simple egret
#

Unity doesn't work with Gradle does it? Or latest versions do but I doubt that since it's for Java stuff

somber nacelle
#

afaik the only thing unity uses gradle for is building for android

regal epoch
#

assets -> external dependency manager -> android resolver -> resolve

somber nacelle
simple egret
#

Yeah that's not from your code

#

Unity is screwing up something here

regal epoch
#

oh my bad

#

you guys don't know what it is by any chance?

simple egret
#

No, we're C# devs

#

The android pros in the channel you've been linked to a few times do, though

desert shard
heady iris
#

are you repeatedly hitting reroll here?

somber nacelle
#

we'd probably have to see that singleton, but i'd imagine objects are probably being dequeued from the generatedUpgrades queue

balmy dove
#

it now doesn't register Sub1/Sub2/Sub3 at all

desert shard
somber nacelle
#

yeah, we'd probably also need to see anywhere else that the queue is accessed

desert shard
silver wharf
#

Why is MonoBehaviour not defined and what can I do about it? I already double checked the IDE setup and nothing seems to be wrong.

somber nacelle
silver wharf
#

its also not autofilling unity syntax like Input.GetKeyDown

somber nacelle
#

!vs

tawny elkBOT
#
Visual Studio guide

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

β€’ Visual Studio (Installed via Unity Hub)
β€’ Visual Studio (Installed manually)

silver wharf
#

i already went through that

#

but it still doesnt work

somber nacelle
#

if you have actually gone through everything in the guide then regenerate project files and restart visual studio

simple egret
desert shard
#

the UsableUpgrades list should not be shrinking

#

that's the issue

#

since I add the previous ones back to it if you reroll

somber nacelle
silver wharf
#

k 1 sec

somber nacelle
heady iris
#

i would specifically check if generatedUpgrades contains what you think it does at the start of the reroll function

desert shard
#

Not too savvy with Queues tbh, not Often I use them

somber nacelle
#

When you use Dequeue it removes the first object in the queue so if you don't put it back then suddenly your queue has fewer objects in it

desert shard
#

I use Dequeue on the first generation. then when reroll is pressed, I dequeue it too

#

oh. perhaps I should have a list along side the queue then?

#

to add them back if rerolling

silver wharf
somber nacelle
#

yeah i didn't need you to ping me again.

silver wharf
#

mb

somber nacelle
#

regenerate project files there and double click a script in unity to open it

silver wharf
#

i tried that

#

it doesnt work

somber nacelle
#

prove it. do it again now and screenshot what the entire IDE looks like with the solution explorer in it open

simple egret
#

Show VS open with a script in view. As well as the solution explorer on the right

silver wharf
#

the solution explorer is the project tab right

simple egret
#

No in VS

somber nacelle
#

no, it's a tab inside of Visual Studio that is literally called Solution Explorer

silver wharf
#

ok

simple egret
#

View > Solution Explorer if it's closed

silver wharf
somber nacelle
#

do you happen to have more than one version of VS2022 installed?

silver wharf
#

wdym that one version

simple egret
#

Nah VS is just freaking out here

#

Where it says Incompatible on the right, right click that and select Reload With Depedencies

silver wharf
#

OH

#

it works thx

hushed needle
#

Hello, I have a problem, with this code this is not true that all the cubes should be red in my scene?(i have some tiles in my scene).

heady iris
#

well, if none of the nodes are walkable, they'll all be red..

mental rover
hushed needle
heady iris
#

that doesn't tell me very much

#

is this a 2D game?

#

you're using a 3D physics query there

desert shard
hushed needle
desert shard
heady iris
cerulean oak
#

whats the problem here?

heady iris
#

well, you tried to use await in a non-async method...

mental rover
somber nacelle
#

you read the error, right?

dusk apex
#

The error is pretty straight forward

#

Google how to use await and async c#

cerulean oak
#

yes but I dont wanna make the method async

wide terrace
#

Then you cannot use await

dusk apex
#

Don't use await

simple egret
#

Then you can't use await in it

desert shard
cerulean oak
#

so how do I await for the task to finish then?

dusk apex
#

Google. This isn't unity specific

simple egret
#

Maybe there's a .GetValue() that's synchronous

dusk apex
#

There's a whole lot of info out there on how to use await.

cerulean oak
#

but im lost

#

like how do I turn from an bunch of async stuff into finally waiting for the async stuff to end

heady iris
#

pretty sure you can just start the task and then check if it's done in a coroutine

#

importantly, you can't run it on another thread and have code immediately run on completion

#

since only the main thread is allowed to mess with the game's state

somber nacelle
#

looks like it's probably firebase which actually has a ContinueWithOnMainThread extension method

heady iris
#

well that's nice!

cerulean oak
#

yes, but in this case I want the main thread to pause

#

until I get the value

heady iris
#

so you want your entire game to freeze

cerulean oak
#

yes

#

i'll implement a loading screen and stuff later

#

but for now I just want to do some quick dirty stuff

#

do I just while (!task.IsCompleted);

#

xd

somber nacelle
#

i mean is there not a non-async overload for GetValue?

cerulean oak
#

doesnt seem to be nope

mental rover
cerulean oak
#

pretty sure if I do that the game actually counts as frozen because it doesnt yield

heady iris
#

well, it's always gonna "count as frozen"

#

the only question is whether it unfreezes at some point

hushed needle
heady iris
#

this assumes you are using 2D colliders, of course

cerulean oak
#

yes but the OS will say its frozen and attempt to close it

heady iris
#

you could very well be using 3D colliders in a 2D game

heady iris
#

this is why non-blocking logic is very important...

cerulean oak
#

ok i'll just implement the loading screen notlikethis

mental rover
heady iris
#

you asked how to set off a grenade and now you're surprised that there's a giant hole in the wall πŸ˜›

cerulean oak
#

in java you can just join a thread to the main one

#

to wait for it

heady iris
#

if you join a thread, you block until that thread finishes

#

so, the exact same thing happens

#

there is no wiggle room here

#

if you block the main thread, the game freezes

cerulean oak
#

the difference is the while(true); uglyness

heady iris
#

that's basically what a WaitForCompletion method would do

#

and it's also exactly what .join() would be in Java

#

just sit there until it's done

fervent furnace
#

will unity allow you to sleep the main thread?

cerulean oak
#

while() doesnt yield tho

heady iris
#

yes

#

because it's synchoronous

#

it blocks the main thread

fervent furnace
#

i just use await task.delay() and hope it will give up the cpu

heady iris
#

the exact same thing happens if you join a thread in Java

wide terrace
#

There also appears to be a Task.RunSynchronously(), which seems to be a fancier way of blocking

cerulean oak
#

thats all I wanted yes

fervent furnace
#

i dont if there is conditional signal in c#

cerulean oak
heady iris
#

it doesn't matter how you make the main thread wait

#

a busy loop or sleeping or whatever

#

the game will freeze

#

you blocked the main thread.

#

you only have two options:

  • block until the data is available
  • don't block and deal with the data not being available yet
fervent furnace
#

oh wait, if you only need to do one task and the main thread must wait for it finish, why dont you put it on main thread?

cerulean oak
#

because the library creates the task

#

not me

heady iris
#

what type does that function return?

#

actually, I'm specifically interested in the result of Child()

fervent furnace
heady iris
#

what type is that thing returning?

heady iris
#

can you point me to the documentation for the type returned by Child?

heady iris
#

i guess that's right

#

and GetValueAsync is returning a C# Task

#

wasn't sure if it was something ~special~

cerulean oak
#

but yes its just a C# task

#

do exceptions not get printed when im on a different thread?

rugged storm
#
float randommod = Random.Range(90, 111) / 100;```
random mod sometimes returns 0, how?
cerulean oak
#

because im starting to lose my mind over code not working

rugged storm
#

(infact almost always returns 0)

fervent furnace
#

try Random.Range(90f,111f)
you are using the int version of random.range

heady iris
#

maybe

somber nacelle
rugged storm
#

this is the whole snippet of code if the issue is elswhere here

cerulean oak
#

yeah im only doing the stuff with gameobjects on the main thread, but I still want to see the exceptions of my fuckups

#

and my debug.logs

prime sinew
rugged storm
#

Oh my b somehow i did not see them

lucid valley
rugged storm
#

Ty!

fervent furnace
cerulean oak
#

no await doesnt create the thread

#

the task does

#

and the exceptions inside the task arent seen in the console

simple egret
#

Awaiting waits for the task to finish and unwraps the exceptions that may have happened in it, so no await means no exceptions reported

#

Also valid if the async method you called returns void

heady iris
#

I want to let the user work with an node graph at runtime. Is there any way to re-use anything from Unity here, or am I gonna have to hand-roll this (or find an asset)?

somber nacelle
#

all the node graph stuff is in the editor assembly, no? so you'd probably have to hand roll it

heady iris
#

yeah.

cerulean oak
#

there is an asset in the store, but its pretty pricey iirc

balmy dove
#

I'm in a jam rn

I thought by putting the IF daisy chain in Awake, I can do the "if two buttons are pressed then use a special weapon and override their individual function" thing as a coroutine
But instead the program did their individual function and entirely didn't register the double input function

heady iris
#

it won't be super elaborate. it'll basically be paths for events to flow through and a few nodes to respond to those events

#

this will not be turing complete, so help me god

#

i imagine it's not that hard if you're willing to accept some performance tradeoffs (e.g. reevaluating the entire graph every time you change anything)

#

and maybe not having the best ergonomics

wide terrace
balmy dove
#

The two button input (overriding their original function) kind of works regarding to melee and boost when they are bunched together in a fixed update function
But at current state they don't work for some reason even when that if statement remained in a Start function (and if it's fixed update the game crashes immediately)

wide terrace
#

If A or B is pressed, wait 0.5 seconds before triggering ability A/B respectively. If the other key is also pressed in that timespan, trigger special ability.

#

It doesn't seem feasible that a human could consistently hit both keys in the same frame simultaneously, so a little delay would account for the timing issue

rugged storm
#

in my SRPG, I have party members

public class PartyMember
{
    public BaseAlly Ally;
    public Stats CurrentStats;

    public PartyMember(BaseAlly ally)//Make a new party member based off ally defaults
    {
        Ally = ally;
        CurrentStats = new Stats(ally.baseStats);
    }
    public PartyMember(BaseAlly ally, Stats stats)//Make a new party member with specific stats
    {
        Ally = ally;
        CurrentStats = stats;
    }
}```

and when I start a level spawn them I instantiate(PartyMember.ally) to the board and set it's stats to PartyMember.CurrentStats, my issue is, When the level is finished how do I go about properly updating the partymembers (I have stored in a list of partymembers in a scriptable object). my though was to have each PartyMember and BaseAlly have an ID and check if thoes match and copy the stats over if they do but im having trouble assigning the IDs properly and im not sure if thats the best way anyway
sage kite
#

So I want a thought bubble to spawn above my character with text inside of the bubble, i have made a script that spawns the bubble and changes the text to what i want it to, but the text dosen't spawn inside the bubble

#

Idk if I'm setting it up wrong?

potent sleet
tawny elkBOT
#
Posting code

πŸ“ƒ Large Code Blocks
Large code blocks should be posted as links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/
https://paste.myst.rs/, https://hastebin.com/

πŸ“ƒ Inline Code
Surround code with three backquotes. Not quotation marks.
To get C# formatting the first line should only contain cs or csharp.
Add a comment with a line number if there is an error message.
```cs
// Your code here
```
Do not share screenshots of code unless requested.

potent sleet
#

and holy shit..

sage kite
#

the file is too long

potent sleet
#

you should be using a JSON or XML

potent sleet
sage kite
#

lol

#

Not a beginner tho

potent sleet
#

yeah everyone says that until it's proven otherwise xD

#

but anyhow, post the code properly please

#

the text is cutoff

knotty sun
sage kite
potent sleet
#

possible,those comments do look ssus

#

no shit..

sage kite
#

lmao

potent sleet
#

flawed logic = gpt

knotty sun
potent sleet
#

"Not a beginner tho
"

#

uses GPT

#

bravo

sage kite
#

Fast and works kinda?

potent sleet
#

clearly doesn't

sage kite
#

Something wrong about using that?

#

Christ why are you guys so toxic tf?

potent sleet
#

no but we don't generally support helping GPT crap

#

it's server rules

knotty sun
dusk apex
ember wedge
#

!code

tawny elkBOT
#
Posting code

πŸ“ƒ Large Code Blocks
Large code blocks should be posted as links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/
https://paste.myst.rs/, https://hastebin.com/

πŸ“ƒ Inline Code
Surround code with three backquotes. Not quotation marks.
To get C# formatting the first line should only contain cs or csharp.
Add a comment with a line number if there is an error message.
```cs
// Your code here
```
Do not share screenshots of code unless requested.

sage kite
#

Aigth aigth, ill look up another solution i guess, got any ideas of how to make text and an object to spawn together?

potent sleet
#

spawn it at the same Vector2/3 position

#

general rule , WorldSpace and UI are on different coordinates

#

UI is screenspace

cold minnow
dusk apex
#

Or use world space ui

sage kite
#

I'll look into it I guess

dusk apex
# cold minnow I've been using GPT to help me identify what the code I need to write does. You'...

That's fine. The issue is usually:

Chat GPT would be useful in seeing how the ai implements something you've done or understand. It isn't so useful for beginners to learn with as they're likely going to be copying code blindly - likely not able to verify the ai solution. You can quickly produce risky error prone code with it though - usually at the expense of requesting debugging from others.

#

Goes with:

Tldr: Debugging AI solutions (suggestions) isn't favorable as anything and everything could be not working. || Minimum expectation is that the person writing the code knows what the code does (they've got to, they're the ones who wrote it) or have a tutorial to be evaluated. ChatGPT is confident and can be useful for generating error prone samples (quickly) but folks aren't wanting to be fixing AI mistakes - they'd rather try helping you understand a tutorial that's concrete (non changing) or expand your own knowledge (one step at a time and not simply having a lot of code with no insurance that any of it works). "Where did they get this from or who told them to write this" - which is often followed by "don't do it" not because it's being lazy but because nobody really wants to fix stuff that nobody really cared or bothered to make sure is working.||

cold minnow
# dusk apex That's fine. The issue is usually: >>> Chat GPT would be useful in seeing how t...

Oh yeah absolutely. Completely agree which is why I've changed how I use it. I now get it to present me with three answers, one correct, two incorrect and I have to identify the correct code and why it's the correct solution.

Though of course 99% of people would ask it to do that job for them and then come here asking others to fix it πŸ˜› I understand why it's frowned upon generally speaking

potent sleet
#

I like GPT when I need randomly generated content
Like
give me a list of 40 random names comma separated

#

menial tasks are ok

dusk apex
#

That would be efficiently using the generator - and you'd know when he's done something wrong.

#

He's just doing the manual labor, you know what you're needing already.

potent sleet
#

Robot 1-X

#

only futurama fans know :P

ashen yoke
#

chat gpt code is like a professional programmer on hallucinogenics

cold minnow
#

But this has also been a learning experience for me too πŸ˜› I'll be sure to make sure I've thoroughly understood anything it's created before I bring any code here. I have had a ton of luck getting it to create a GUIStyle Pause Menu that displays the last rendered frame on screen whilst pausing rendering in the background. I'm having such a blast with Unity in general right now

dusk apex
#

Assuming the complications of level completion refers to scene load and retaining data

potent sleet
#

Quick curiosity ,

does anyone know how to get TryGetComponent to work like GetComponentInParent ?

iirc with my testing it doesn't traverse up the hirerchy

ashen yoke
#

write your own

potent sleet
#

thought so
annoyed typing
var parent = thing.GetComponentInParent<Foo>();
if(parent != null)

vapid bough
#

im getting null reference exception from this line. does anyone know why?

#

to be clear i did define playerCam

dusk apex
#

Player cam is null

vapid bough
dusk apex
#

There is no camera with main camera tag in scene

vapid bough
#

there is

dusk apex
#

Camera.main would return null when there is no camera with main camera tag in scene.

#

You've got to check the tag.

#

The compiler is almost never wrong

vapid bough
#

looks fine

ashen yoke
#

then its not present at the time the of the assignment in your script

dusk apex
#

The error possibly lies elsewhere - you haven't shown us the error from the console tab.

ashen yoke
#

or that

dusk apex
#

Human error is likely probable

dusk apex
#

Show us the player controller script

vapid bough
#

im using fish-net

#

does that have to do with something?

dusk apex
#

It should've been a move function call from the player controller that threw the error

vapid bough
#

this is my move function

dusk apex
#

How to post!code

tawny elkBOT
#
Posting code

πŸ“ƒ Large Code Blocks
Large code blocks should be posted as links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/
https://paste.myst.rs/, https://hastebin.com/

πŸ“ƒ Inline Code
Surround code with three backquotes. Not quotation marks.
To get C# formatting the first line should only contain cs or csharp.
Add a comment with a line number if there is an error message.
```cs
// Your code here
```
Do not share screenshots of code unless requested.

ashen yoke
#

where does the camera assignment happen

vapid bough
#

hold on il paste this code i the thing

primal wind
dusk apex
#

External code service is recommended

vapid bough
ashen yoke
#

when is OnStartClient called

vapid bough
#

when you connect with the fish-net server

#

before awake

#

im 99% sure of that

ashen yoke
#

then thats the problem

#

either move or lazy init

vapid bough
#

the script is in a prefab it only exists after you connect

ashen yoke
#

i dont see other explanation

#

nothing prevents anything from calling methods on prefabs

#

before instantiation, or instantiate disabled, call/init, enable

vapid bough
#

they need to be in the scene to call the update fuction no?

#

or is that not how unity works

ashen yoke
#

since i wrote similar systems that hijack scene initialization my guess is that the framework youre using is loading first, disables all roots in the scene, performs init, then enables

#

probably easy to test if you add Debug.Break() in OnStartClient

#

and observe scene state

#

if the objects were disabled before awake, there wont be an awake until they are enabled again

#

similarly if you disable prefab before instantiation there wont be awake

vapid bough
#

your right

unreal valley
#

What are some troubleshooting methods to do to find out why a Class will not show in the inspector even if it is labeled with [Serializable]

vapid bough
#

update runs before start client

unreal valley
#
using System;
using UnityEngine;

[Serializable]
public abstract class JobBase
{
    public virtual string JobName => "No Name Job";
    public virtual LevelingSystem LevelingSystem => new LevelingSystem();
}
dusk apex
#

To the Unity inspector that is.

ashen yoke
#

abstract classes arent instantiatable

unreal valley
#

Ahhhhhhhh. shoot.

ashen yoke
#

you cant create an instance of it

dusk apex
#

They wouldn't know what kind of child should be shown in the inspector

unreal valley
#

Should I go the ScriptableObject route then I guess...?

ashen yoke
#

there is SerializeReference attribute

#

but it requires you to understand quite a lot

unreal valley
#

What is the jist of that?

brave radish
ashen yoke
#

no cross mono refs serialized

twin hull
#

why is it abstract in the first place

unreal valley
#

Ill take a look into it.

ashen yoke
#

or rather within the same serialized unity object

dusk apex
#

I don't see any abstract methods, this could very well be a regular class?

unreal valley
ashen yoke
#

abstract is used to enforce that this class should only serve as a base for other

unreal valley
#

Yeah thats essentially what I was going for

swift falcon
#

can I use DontDestroyOnLoad in a way that when switching scenes (each has their own player object) and you go back to the first one the position remains?

twin hull
#

abstract locks it basically

#

just remove abstract and it will work

unreal valley
#
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Job_Warrior : JobBase
{
    public override string JobName => "Warrior";
}

ashen yoke
#

its fine to not have any abstract methods in abstract class

unreal valley
#

I know its bare bones, but its what I was going for.

ashen yoke
#

its also fine to treat it as a normal class, adding fields etc

#

the purpose still will be served

unreal valley
#

What do you mean?

ashen yoke
#

you cant instantiate it, only inherit

twin hull
#

yes, but we're not chatgpt

unreal valley
dusk apex
unreal valley
ashen yoke
#

yes use unity methodology save yourself headaches

#

when in rome

twin hull
#

@unreal valley your entire problem is just that you added abstract. for what you wanted to do, it's not needed.

dusk apex
#

You'd forgo having to use polymorphism or inheritance simply to define data such as name and whatnot, that would do so through inline code.

ashen yoke
#

how is that a problem

unreal valley
#

I was trying to be smarter than I actually am and was going for a OOP approach

dusk apex
#

More design friendly outside of pure code.

twin hull
#

it's not like OOP is wrong in this case, not required either though

#

abstract is a keyword for "do not use this, ONLY inherit"

ashen yoke
#

yes

#

question closed

primal wind
#

So it's like an implicit interface?

twin hull
#

honestly i don't even know why abstract exists, never used it

ashen yoke
primal wind
#

Oh yeah

#

I honestly never used abstract

#

so i don't know much about it

#

I only learned about it because of our Java classes

unreal valley
#

Yeah im just going to scrap what I was doing and go with SciptableObjects lol

swift falcon
#

abstract methods are ment to be overridend xD

gray mural
#

is it true that FindGameObjectWithTag is bad to use?

unreal valley
#

Just make a Job Class that grabs the data from the SO

ashen yoke
#

@unreal valley and there you can use abstract

swift falcon
#

virutual methods can be override and also use the same code from the base function

ashen yoke
#
abstract class Job : ScriptableObject
primal wind
twin hull
#

i'd actually recommend not using SO

primal wind
#

It's fine

gray mural
primal wind
#

As long as you don't spam it it's fine

ashen yoke
#

the Find grows slower with amount of gameobjects in the scene

primal wind
#

Yeah that too

#

Oh i just had a dumb idea. I'll have to add it later

unreal valley
ashen yoke
twin hull
#

@unreal valley you never need to abstract anything.

#

abstract is essentially a lock.

fervent furnace
#

if there are few references to be assigned, manually assign them unless the script have to store many references to GO

ashen yoke
#

on accident, for example, youll enforce that only concrete Job implementations can be created

#

it simply a good practice that in case of data can save you some headache down the line

unreal valley
#

So do I want the Job an SO or the JobData an SO?

twin hull
#

@unreal valley literally just erase "abstract" in your class and it'll work

#

idk why i need to repeat it so many times

ashen yoke
unreal valley
ashen yoke
#

for one there is nothing in the class to serialize

unreal valley
#
private void Awake()
    {
        Job_Warrior warrior = new();

        jobs.Add(warrior);

        foreach (JobBase job in jobs) jobNames.Add(job.JobName);
    }

ashen yoke
#

unity wont serialize properties and methods

#

not without [field:SerializeField] but its a bad practice imo

eager aspen
#

im having a weird issue when spawning a prefab. So basically I have a script that has the sole purpose of spawning a random sound effect player.

    {
        chooseClip();
        createSoundSource(worldPosition);
        soundSource.spatialize = true;
        soundSource.maxDistance = maxDistanceFor3DSound;
        if (randomizePitch)
        {
            soundSource.pitch = Random.Range(pitchRange.x, pitchRange.y);
        }
        soundSource.clip = chosenClip;
        soundSource.Play();
        Destroy(soundSource.gameObject,clipLength);
    }

private AudioSource createSoundSource(Vector3 position)
    {
        GameObject g = Instantiate(new GameObject(),transform.position,quaternion.identity);
        g.name = "soundPlayer";
        soundSource = g.AddComponent<AudioSource>();
        soundSource.playOnAwake = false;
        soundSource.loop = false;
        return soundSource;
    }```

the issue that im having though is that it is *Also* Spawning a empty game object with nothing on it just named "new game object" ive isolated it to this script (if i dont call play audio it doesnt happen) but i cant see why its spawning two objects.